-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem31to39.py
More file actions
153 lines (97 loc) · 2.76 KB
/
Problem31to39.py
File metadata and controls
153 lines (97 loc) · 2.76 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
# problem 31
def compute_gcd(x, y):
gcd = 1
if x % y == 0:
return y
for k in range((y / 2), 0, -1):
if x % k == 0 and y % k == 0:
gcd = k
break
return gcd
print(compute_gcd(2, 5))
print(compute_gcd(12, 17))
print(compute_gcd(4, 6))
print("--------------Problem 31 End--------------------------")
# problem 32
def compute_lcm(x, y):
z = max(x, y)
while True:
if z % x == 0 and z % y == 0:
lcm = z
break
z = z + 1
return lcm
print(compute_lcm(2, 5))
print(compute_lcm(15, 17))
print(compute_lcm(4, 6))
print("--------------Problem 32 End--------------------------")
# problem 33
def sum_of_numbers(x, y, z):
if x == y or y == z or x == z:
return 0
else:
return x + y + z
print(sum_of_numbers(2, 1, 2))
print(sum_of_numbers(1, 2, 3))
print(sum_of_numbers(1, 1, 1))
print("--------------Problem 33 End--------------------------")
# problem 34
def sum_of_two(x, y):
z = x + y
if 15 <= z <= 20:
return 20
else:
return z
print(sum_of_two(10, 6))
print(sum_of_two(10, 2))
print(sum_of_two(10, 12))
print("--------------Problem 34 End--------------------------")
# problem 35
def test_number5(x, y):
if x == y or (x + y) == 5 or abs(x - y) == 5:
return True
return False
print(test_number5(7, 2))
print(test_number5(3, 2))
print(test_number5(2, 2))
print("--------------Problem 35 End--------------------------")
# problem 36
def addNumbers(x, y):
if isinstance(x, int) and isinstance(y, int):
return x + y
else:
raise TypeError("Input Must be Integer")
print(addNumbers(1, 2))
# print(addNumbers("abc", 2))
print("--------------Problem 36 End--------------------------")
# problem 37
def personDetails():
name = "Kiran Rao"
age = 21
address = "Bangalore, Karnataka, India"
return "Name: {}\nAge: {}\nAddress: {}".format(name, age, address)
print(personDetails())
print("--------------Problem 37 End--------------------------")
# problem 38
def computeFormula(x, y):
sum = x + y
return sum * sum
print(computeFormula(4, 3))
print("--------------Problem 38 End--------------------------")
# problem 39
amt = 10000
int = 3.5
years = 7
future_value = amt * ((1 + (0.01 * int)) ** years)
print(round(future_value, 2))
print("--------------Problem 39 End--------------------------")
# problem 40
import math
def distanceBetweenPoints(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
print(distanceBetweenPoints(4, 0, 6, 6))
print("--------------Problem 40 End--------------------------")
# problem 6
print("--------------Problem 6 End--------------------------")
# problem 6
print("--------------Problem 6 End--------------------------")