-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab2.py
More file actions
156 lines (113 loc) · 3.85 KB
/
Lab2.py
File metadata and controls
156 lines (113 loc) · 3.85 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
import calendar
# Calculator
number1 = float(input("Enter first number: "))
number2 = float(input("Enter second number: "))
print()
print("operation \n 1. addition -> + \n 2. subtraction -> - \n 3. multiplication -> x \n 4. division -> \ \n 5. modulo -> %")
operation = int(input("Enter operation number: "))
operationSymbol = ["+", "-", "*", "/", "%"]
if operation > 5:
print("Operation not possible")
def calculation(number1, number2, operation):
if operation == 1:
sum = number1 + number2
return sum
elif operation == 2:
sub = number1 - number2
return sub
elif operation == 3:
mul = number1 * number2
return mul
elif operation == 4:
div = number1 / number2
return div
elif operation == 5:
mod = number1 % number2
return mod
else:
exit()
if int(number1) == float(number1):
number1 = int(number1)
if int(number2) == float(number2):
number2 = int(number2)
calculatedAnswer = calculation(number1, number2, operation)
if int(calculatedAnswer) == float(calculatedAnswer):
calculatedAnswer = int(calculatedAnswer)
print(f"{number1} {operationSymbol[operation - 1]} {number2} =" , calculation(number1, number2, operation))
# Union, Compliment and Intersection
array1 = [1, 1, 3, 9, 5, 2]
array2 = [2, 3, 8, 9, 7, 2]
array1WithoutDuplicates = []
array2WithoutDuplicates = []
arraySolution = []
print(f"array1 = {array1}")
print(f"array2 = {array2}")
def removingDuplicates():
for i in array1:
if i not in array1WithoutDuplicates:
array1WithoutDuplicates.append(i)
for j in array2:
if j not in array2WithoutDuplicates:
array2WithoutDuplicates.append(j)
def clearingAllArrays():
array1WithoutDuplicates.clear()
array2WithoutDuplicates.clear()
arraySolution.clear()
def resetAll():
clearingAllArrays()
removingDuplicates()
def operationSet():
removingDuplicates()
for k in array1WithoutDuplicates:
if k not in array2WithoutDuplicates:
array2WithoutDuplicates.append(k)
array2WithoutDuplicates.sort()
# Solution for Union
print(f"union is {array2WithoutDuplicates}")
resetAll()
for i in array1WithoutDuplicates:
for j in array2WithoutDuplicates:
if i == j:
arraySolution.append(i)
# solution for intersection
arraySolution.sort()
print(f"intersection is {arraySolution}")
resetAll()
for i in array2WithoutDuplicates:
if i not in array1WithoutDuplicates:
arraySolution.append(i)
print(f"compliment of array1 with respect to array2 is {arraySolution}")
resetAll()
for i in array1WithoutDuplicates:
if i not in array2WithoutDuplicates:
arraySolution.append(i)
print(f"compliment of array2 with respect to array1 is {arraySolution}")
resetAll()
for i in array1WithoutDuplicates:
for j in array2WithoutDuplicates:
if i == j:
arraySolution.append(i)
array2WithoutDuplicates.clear()
for i in array1WithoutDuplicates:
if i not in arraySolution:
array2WithoutDuplicates.append(i)
# solution for intersection
arraySolution.sort()
print(f"Difference of array1 - array2 is {array2WithoutDuplicates}")
resetAll()
for i in array2WithoutDuplicates:
for j in array1WithoutDuplicates:
if i == j:
arraySolution.append(i)
array1WithoutDuplicates.clear()
for i in array2WithoutDuplicates:
if i not in arraySolution:
array1WithoutDuplicates.append(i)
# solution for intersection
arraySolution.sort()
print(f"Difference of array2 - array1 is {array1WithoutDuplicates}")
operationSet()
# Calender
yy = int(input("Enter valid year: "))
mm = int(input("Enter valid month: "))
print(calendar.month(yy, mm))