forked from zhiwehu/Python-programming-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq1.py
More file actions
72 lines (55 loc) · 1.3 KB
/
q1.py
File metadata and controls
72 lines (55 loc) · 1.3 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
import math
def printnumbers():
numbers = []
k=1
for number in range(2000,3201)[::k]:
if (number%7 is 0) and (number%5 is not 0):
numbers.append(number)
if k is not 7:
k=7;
print(numbers)
def fact(n):
fa = 1
for d in range(n,1,-1):
fa = fa * d
return fa;
#n = int(input('Number --> '))
#print(fact(n))
#Problem 3, asks to print a dictionary where values are square of the key. n is input.
def sqdic(n):
return {x: x*x for x in range(1,n+1)}
def sqdic2(n):
d = {}
for x in range(1,n+1):
d[x] = x*x;
return d
#Problem 4, str split and rsplit methods use
def splitthestr(s):
print(type(s))
slist = s.split(',')
print(slist)
print(tuple(slist))
#sa = input("give numbers")
#splitthestr(sa)
class TestClass:
def __init__(self, name):
self.name = name;
def getwelcomemessage(self):
print('hello {}'.format(self.name))
#tc = TestClass("Jubayer")
#tc.getwelcomemessage()
# problem 6
def calculateQ(D):
C = 50
H = 30
Q = math.sqrt((2*C*D)/H)
return math.floor(Q)
def getnumbers(st):
l = st.split(',')
nl = [int(x) for x in l]
return nl
#s = input("--> Numbers: ")
#l = [calculateQ(x) for x in getnumbers(s)]
#l = map(str, l)
#print (','.join(l))
#problem 7