-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions
More file actions
168 lines (125 loc) · 3.24 KB
/
Functions
File metadata and controls
168 lines (125 loc) · 3.24 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
------------------Find Factorials using Recurssion------------------------
'''def tri_recursion(k):
if (k>0):
result = k+tri_recursion(k-1)
print(result)
else:
result=0
return result
print("")
tri_recursion(6)
#print(my_function(5))
#print(my_function())'''
---------------------Area of circle------------
'''
#areaofcircle
def area_circle(r):
result= 3.14*r**2
return result
print(area_circle(6))'''
'''
-------------------------prime or not-------------------
def my_function(x):
if x==1:
print('num is not prime')
elif x>1:
for i in range(2,x):
if(x % i) == 0:
print("number is not prime")
break
else:
return ("number is prime")
else:
print('num is not prime')
print(my_function(29))
lis=[1,4,10,12,11,31,77,67]
prime=[]
for i in lis:
c=0
for j in range(1,i):
if i%j==0:
c+=1
if c==1:
prime.append(i)
print(prime)
----------------reverse string -------------------------
def rev_fun(X):
#return X[::-1] # to reverse like mirror image
word = X.split(' ')
reverse_sentence= ' '.join(reversed(word)) # to reverse entire sentence
return reverse_sentence
-----------------palindrome--------------------
print(rev_fun(" mummy pappa?")) '''
'''
def my_fun(s):
if s == s[::-1]:
print("palindrome")
else:
print("not palindrome")
my_fun('new string')
my_fun('asa') '''
# op: not palindrome
'''
------------------- factorial using recurssion -------------------
def fact_rec(num):
if num <0:
raise ValueError("factorial of num is not defined")
elif num ==0:
return 1
else:
return num * fact_rec(num-1)
num=-1
print("factorial of" , num, "is", fact_rec(num))'''
'''
------------------square root of list---------------
import math
def sqr_fun(arr):
s=[]
for i in range(len(arr)):
s.append(math.sqrt(arr[i]))
return s
list=[4,8,3,5]
result = sqr_fun(list)
print(result)
------------------sqr of num ------------
def sqr_fun(num):
return num**2
print(sqr_fun(200))
---------------- even or odd=------------------
def ev_od(num):
if num%2==0:
print("num is even")
else:
print("num is odd")
ev_od(8)
-----------calculate area of triangle --------
def area_tri(b,h):
return 1/2 * b * h
print(area_tri(3,9))
-----------------table of given no.--------------------
def mul_table(num):
m=[]
n=1
while n<=10:
m.append(num*n)
n+=1
return m
print(mul_table(20))
------------intersection of two list-----------
def str_fun(Country,towns):
result=[value for value in Country if value in towns]
#list(set(Country) & set(towns))
return result
country=["india",'america','japan','china']
towns=["pune","mumbai","delhi","india"]
print(str_fun(country,towns))
----------------- leap year or not ------------
def year_check(year):
if year %100 == 0 and year % 400==0:
return "leap"
elif year % 100 !=0 and year %4==0:
return "leap"
else:
return "error"
year=2001
print(year_check(year)) '''