-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexaples3.py
139 lines (89 loc) · 2.01 KB
/
exaples3.py
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
x = 5
s = 'Mahmod Ahmed'
print(type(x))
print(type(s))
print('---------------------')
# python if else example:
x = 500
if x > 600:
print('x is bigger than 600')
else:
print('x is smaller than 600')
print('---------------------')
#python elif example:
x = 100
if x == 200:
print('x = 200')
elif x == 150:
print('x = 150')
elif x == 300:
print('x = 300')
else:
print('this is the default option')
print('rest of the code')
print('---------------------')
#python nested if example:
x = 100
if x < 200:
print('x is less than 200')
if x == 150:
print('x = 150')
elif x == 50:
print('x = 50')
elif x < 50:
print('x is less than 50')
print('rest of the code')
print('---------------------')
#if with boolean operators
name = "mahmod"
age = 21
if name == "mahmod" and age == 21:
print("welcome mahmod")
if name == "mahmod" or name == "ahmad":
print("you are not mahmod")
print('---------------------')
#python single if example:
x = 100
if x == 100: print('x = 100')
print('---------------------')
#python single if else example:
x = 5
print('x = 5') if x == 5 else print('x != 5')
print('---------------------')
#python conditions example:
birds = {"parakeet": 1, "parrot": 2}
if "parrot" in birds:
print('there is a parrot')
print('---------------------')
#python conditions example:
birds = {"parakeet": 1, "parrot": 2}
if "automobile" not in birds:
print('not found')
print('---------------------')
#python conditions example:
x = 5
y = 6
z = 3
if all([x == 5, y == 6, z == 3]):
print('all are true')
if any([x == 2, y == 8, z == 9]):
print('not all are true')
print('---------------------')
#python conditions example:
a = 1
b = 2
if a == 1 and b == 2:
print(True)
if a == 0 or b == 2:
print(True)
if not (a == 1 and b == 3):
print(True)
if a != 0 and b != 3:
print(True)
print('---------------------')
#python conditions example:
x = 1
if x in (0,2,4):
print('match')
else:
print('not found')