-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperators.py
More file actions
141 lines (109 loc) · 2.96 KB
/
operators.py
File metadata and controls
141 lines (109 loc) · 2.96 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
'''Arithmetic Unary Comparison Bitwise Assignment
Logical Membership Identity Conditional'''
#ARITHMETIC OPERATORS
'Addition'
a=5
b=3
print("ADDITION")
print("The value of a is :-",a)
print("The value of b is :-",b)
print("Addition of a and b is :-",a+b)
'Substraction'
print("Substraction of a and b is :-",a-b)
'Multiplication'
print("Multiplication of a and b is :-",a*b)
'Divison'
print("Divison of a and b is :-",a/b)
'Power'
print("Power of a and b is :-",a**b)
'Floor Divison'
print("Floor Divison of a and b is :-",a//b)
'Modulus'
print("Modulus of a and b is :-",a%b)
print("-----------------------------------------")
a = [1,2,3]
b = [4,5,6]
print("List Individual Addition :-",a[0]*b[0])
print("List Addition :-",a+b)
a = (1,2,3)
b = (4,5,6)
print("Tuple Individual Addition :-",a[0]+b[0])
print("Tuples Addition :-",a+b)
a = {1:'a',2:'b',3:'c'}
b = {4:'d',5:'e',6:'f'}
print("Dictionaries can't be added")
print("-----------------------------------------")
#BOOLEAN OPERATORS
'''import random
a=random.randint(1,9)
b=random.randint(1,9)
ans=eval(input("What is "+str(a)+" "+str(b)+" :- "))
print("Your ans is :-",a+b==ans)'''
print("-----------------------------------------")
#COMPARSION OPERATORS
print("COMPARSION")
print(10>5)
print(True>False)
print(5.5>5)
print('x'>'@')
print('Z'<'5')
print("Comparison operators compares the ASCII ")
a = [1,200,2]
b = [1,200,3]
print(a<=b)
print("-----------------------------------------")
print("-----------------------------------------")
#BITWISE OPERATORS
print("BITWISE")
'''AND,OR,NOT,LEFT SHIFT,RIGHT SHIFT'''
print(0 & 1)
print(1 | 2)
print(1 ^ 2) #Different True, Same False
print(~ 100) #-(n+1)
print(5 << 2)
print(5 >> 2)
print("-----------------------------------------")
print("-----------------------------------------")
#LOGICAL OPERATORS
print("LOGICAL")
print(0 and 1)
print(0 or 50)
print((2>3) and (3>2))
print((2>3) or (3>2))
print(not((2>3) or (3>2)))
print("-----------------------------------------")
print("-----------------------------------------")
#IDENTITY OPERATORS
print("IDENTITY")
print("It compares the memory allocation of two identity operators")
a = 5
b = 5
print(a is b)
print(a is 5)
print(a is not 5)
print(1 is 1)
print('a' is 'a')
a = [1,2,3]
b = [1,2,3]
print(a is b) #Memory Allocation is different
print("-----------------------------------------")
print("-----------------------------------------")
#MEMBERSHIP OPERATORS
print("MEMBERSHIP")
b = ['a','b','c']
print('b' in b)
print('d' in b)
print("-----------------------------------------")
print("-----------------------------------------")
#CONDITIONAL OPERATORS
print("CONDITIONAL")
a = 10
b = 5
if a>b:
print("a is greater")
elif a<b:
print("b is greater")
else:
print("a and b are equal")
print("-----------------------------------------")
print("-----------------------------------------")