-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBadal_Prasad_Singh_12219981_Python_Assignment.py
126 lines (102 loc) · 2.33 KB
/
Badal_Prasad_Singh_12219981_Python_Assignment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# def fac(n):
# if n<=1:
# return 1
# else:
# return n*fac(n-1)
#
# print(fac(4))
# def sum_even(x):
# s=0
# for i in x:
# if i%2==0:
# s+=i
# return s
# print(sum_even([1,2,3]))
# def palindromestring(s):
# return s==s[::-1]
# print(palindromestring("MAM"))
# def max_three(a,b,c):
# return max(a,max(b,c))
# print(max_three(2,3,4))
def sq(a):
return a*a
def prime(n):
f=0
for i in range(2,n-1):
if n%i==0:
f+=1
return True if f==0 else False
print(prime(7))
def rev_list(x):
return x[::-1]
def common_list(a,b):
return list(set(a) & set(b))
print(common_list([1,2,3],[2,3,4]))
def av_list(x):
return sum(x)/len(x)
def gcd(a, b):
if(b == 0):
return a
else:
return gcd(b, a % b)
def words(s):
return s.count(' '+1)
def fib(num):
n1, n2 = 0, 1
for i in range(2, num):
n3 = n1 + n2
n1 = n2
n2 = n3
print(n3, end=" ")
def longstr(x):
max_str=""
max_len=0
for i in x:
if len(i)>max_len:
max_str=i
return max_str
def CheckLeap(Year):
if((Year % 400 == 0) or
(Year % 100 != 0) and
(Year % 4 == 0)):
print("Given Year is a leap Year");
else:
print ("Given Year is not a leap Year")
def area_rec(l,b):
return l*b
def ctof(x):
fahrenheit_temp = x * 1.8 + 32
return fahrenheit_temp
def sqRoot(n, l):
x = n
count = 0
while (1):
count += 1
root = 0.5 * (x + (n / x))
if (abs(root - x) < l):
break
x = root
return root
def vcount(x):
c=0
for i in x.lower():
if i in 'aeiou':
c+=1
return c
def find_median(numbers):
numbers.sort()
n = len(numbers)
if n % 2 == 1:
median = numbers[n // 2]
else:
middle1 = numbers[(n // 2) - 1]
middle2 = numbers[n // 2]
median = (middle1 + middle2) / 2
return median
import random
import string
def password(length):
characters = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(characters) for _ in range(length))
return password
print(password(7))