Skip to content

Commit ab93daf

Browse files
#1 - Python
1 parent 3780966 commit ab93daf

File tree

1 file changed

+247
-0
lines changed

1 file changed

+247
-0
lines changed
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
### Python Operators ###
2+
3+
#! Arithmetic
4+
5+
# Addition
6+
print(4 + 5)
7+
8+
# Subtraction
9+
print(5 - 4)
10+
11+
# Multiplication
12+
print(5 * 5)
13+
14+
# Division
15+
print(15 / 3)
16+
17+
#* Modulus
18+
print(10 % 2)
19+
20+
# Exponent
21+
print(6**2)
22+
23+
# Floor Division
24+
print(15 // 2)
25+
26+
#! Comparison Operators
27+
28+
# Equal
29+
print(2 == 2)
30+
31+
#*Not Equal
32+
print(2 != 2)
33+
34+
# Less Than
35+
print(5 < 10)
36+
37+
# Greater Than
38+
print(8 > 10)
39+
40+
# Less Than Or Equal To
41+
print(8 <= 8)
42+
43+
# Greater Than Or Equal To
44+
print(8 >= 8)
45+
46+
#! Assignment Operators
47+
48+
# Assignment Operator
49+
x = "Hello"
50+
print(x)
51+
52+
# Addition Assignment
53+
my_num = 10
54+
my_num += 8
55+
print(my_num)
56+
57+
# Subtraction Assignment
58+
my_num = 10
59+
my_num -= 5
60+
print(my_num)
61+
62+
# Multiplication Assignment
63+
my_num = 10
64+
my_num *= 2
65+
print(my_num)
66+
67+
# Division Assignment
68+
my_num = 20
69+
my_num /= 2
70+
print(my_num)
71+
72+
# Remainder Assignment
73+
my_num = 50
74+
my_num %= 5
75+
print(my_num)
76+
77+
# Exponent Assignment
78+
my_num = 5
79+
my_num **= 2
80+
print(my_num)
81+
82+
# Floor Division Assignment
83+
my_num = 9
84+
my_num //= 2
85+
print(my_num)
86+
87+
#! Logical Operators
88+
89+
# And
90+
print(True and True)
91+
print(False and True)
92+
93+
# Or
94+
print(True or True)
95+
print(False or True)
96+
97+
# Not
98+
print(not False)
99+
100+
#! Membership Operators
101+
102+
# In
103+
my_list = [1, 5, 8, 5, 6]
104+
print(1 in my_list)
105+
print(10 in my_list)
106+
107+
# Not In
108+
my_list = [1, 5, 8, 5, 6]
109+
print(1 not in my_list)
110+
print(10 not in my_list)
111+
112+
#! Identity Operators
113+
114+
# Is
115+
num_one = 1
116+
num_two = 2
117+
print(num_one is num_one)
118+
print(num_one is num_two)
119+
120+
num_one = 1
121+
num_two = num_one
122+
print(num_one is num_one)
123+
print(num_one is num_two)
124+
125+
# Is Not
126+
num_one = 1
127+
num_two = 2
128+
print(num_one is num_one)
129+
print(num_one is num_two)
130+
131+
num_one = 1
132+
num_two = num_one
133+
print(num_one is not num_one)
134+
print(num_one is not num_two)
135+
136+
#! Bitwise Operators
137+
138+
# Binary And
139+
print(1 & 0)
140+
141+
# Binary Or
142+
print(1 | 0)
143+
144+
# Binary Xor
145+
print(1 ^ 0)
146+
147+
# Binary Complement
148+
print(~1)
149+
150+
# Binary Left Shift
151+
print(10 << 2)
152+
153+
# Binary Right Shift
154+
print(40 >> 2)
155+
156+
###* Control Structures ###
157+
158+
#! Selection Statements
159+
160+
num_one = 55
161+
num_two = 10
162+
163+
if num_one > num_two:
164+
print(f'Num one {num_one} is greater than num two {num_two}.')
165+
elif num_one < num_two:
166+
print(f'Num two {num_two} is greater than num two {num_one}.')
167+
else:
168+
print(f'Num one {num_one} and number two {num_two} are equal.')
169+
170+
num_one = 55
171+
num_two = 100
172+
173+
if num_one > num_two:
174+
print(f'Num one {num_one} is greater than num two {num_two}.')
175+
elif num_one < num_two:
176+
print(f'Num two {num_two} is greater than num two {num_one}.')
177+
else:
178+
print(f'Num one {num_one} and number two {num_two} are equal.')
179+
180+
num_one = 55
181+
num_two = 55
182+
183+
if num_one > num_two:
184+
print(f'Num one {num_one} is greater than num two {num_two}.')
185+
elif num_one < num_two:
186+
print(f'Num two {num_two} is greater than num two {num_one}.')
187+
else:
188+
print(f'Num one {num_one} and number two {num_two} are equal.')
189+
190+
my_var_one = True
191+
my_var_two = True
192+
193+
if my_var_one and my_var_two:
194+
print('All of the items are True')
195+
else:
196+
print('One of the Items is False')
197+
198+
my_var_one = True
199+
my_var_two = False
200+
201+
if my_var_one and my_var_two:
202+
print('All of the items are True')
203+
else:
204+
print('One of the Items is False')
205+
206+
my_var_one = True
207+
my_var_two = False
208+
209+
if my_var_one or my_var_two:
210+
print('One of the items is True')
211+
else:
212+
print('All of the Items are False')
213+
214+
my_var_one = False
215+
my_var_two = False
216+
217+
if my_var_one or my_var_two:
218+
print('One of the items is True')
219+
else:
220+
print('All of the Items are False')
221+
222+
#! Repetition
223+
224+
counter = 0
225+
226+
while counter <= 10:
227+
print(f'Counting to ten: {counter}')
228+
counter += 1
229+
230+
my_nums = [1 ,5 ,4 ,8, 10, 15]
231+
232+
for num in my_nums:
233+
print(num) if num != 5 else print(f'I\'m a five')
234+
235+
#! Optional Challenge
236+
237+
print('---Optional Challenge----')
238+
239+
for num in range(10, 56):
240+
if num == 55:
241+
print(num)
242+
243+
if num % 2 == 0 and num % 3 != 0 and num != 16:
244+
print(num)
245+
246+
247+

0 commit comments

Comments
 (0)