-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditional.py
More file actions
executable file
·69 lines (51 loc) · 813 Bytes
/
conditional.py
File metadata and controls
executable file
·69 lines (51 loc) · 813 Bytes
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 9 22:18:09 2021
@author: maherme
"""
#%%
# Basic.
a = 6
if a < 5:
print('a < 5')
else:
print('a >= 5')
#%%
# Nested.
a = 5
if a < 5:
print('a < 5')
else:
if a < 10:
print('5 <= a < 10')
else:
print('a >= 10')
#%%
# Branching.
a = 25
if a < 5:
print('a < 5')
elif a < 10:
print('5 <= a < 10')
elif a < 15:
print('10 <= a < 15')
elif a < 20:
print('15 <= a < 20')
else:
print('a > 20')
#%%
# Conditional expresion: X if (condition is true) else Y
# It is not used to manage blocks of code.
a = 25
b = 'a < 5' if a < 5 else 'a >= 5'
print(b)
#%%
# The above code is the same as:
a = 25
if a < 5:
b = 'a < 5'
else:
b= 'a >= 5'
print(b)
#%%