Skip to content

Commit 5cdb0ef

Browse files
Chen GaoChen Gao
Chen Gao
authored and
Chen Gao
committed
add exercise python file
1 parent 22bb9b3 commit 5cdb0ef

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

python_exercises.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
################# question 1 ###################
2+
def q1_div(x,y):
3+
l=[]
4+
for i in range(x,y):
5+
if (i%7==0) and (i%5!=0):
6+
l.append(str(i))
7+
l_cont = ','.join(l)
8+
print(type(l_cont),(l_cont))
9+
10+
################# question 2 ###################
11+
def q2_factorial(x):
12+
for i in range(x-1,1,-1):
13+
x=x*i
14+
print(x)
15+
def q2_factorial_s(x):
16+
if x==0:
17+
return 1
18+
else:
19+
return x*q2_factorial_s(x-1)
20+
21+
################# question 3 ###################
22+
def q3_sqr(x):
23+
d = {}
24+
for i in range(1,x+1):
25+
d[i]=i*i
26+
return(d)
27+
28+
################# question 4 ###################
29+
def q4_listtuple_s():
30+
values=input()
31+
l=values.split(",")
32+
t=tuple(l)
33+
print(l)
34+
print(t)
35+
36+
37+
if __name__ == "__main__":
38+
q4_listtuple_s()

0 commit comments

Comments
 (0)