-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconditionalstatements.py
85 lines (60 loc) · 1.29 KB
/
conditionalstatements.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
# Comparisons:
# Equal: ==
# Not Equal: !=
# Greater Than: >
# Less Than: <
# Greater or Equal: >=
# Less or Equal: <=
# Object Identity: is
if True:
print('Condition was True')
if False:
print('Condition False')
language = 'Java' # python does not have a switch case, cannot validate two items
if language == 'python':
print('language is python')
elif language == 'Java':
print('language is Java')
elif language == 'JavaScript':
print('language is JavaScript')
else:
print('no match')
# and
# or
# not
user = 'Admin'
logged_in = False #True False statements do not need ''
if user == 'Admin' and logged_in:
print('Admin page')
else:
print('Bad Creds')
if not logged_in:
print('Please logged in')
else:
print('Welcome')
# False Values: Conditions that alwasy evaluate to False
# False
# None
# Zero of any numeric type
# Any empty sequence, For example, '', (), [].
# Any empty mapping. For example, {}.
Condition = False
if Condition:
print('evaluated to True')
else:
print('evaluated to False')
Condition2= None
if Condition2:
print('evaluated to true')
else:
print('evaluated to False')
Condition3 = 0
if Condition3:
print('evaluated to True')
else:
print('evaluated to False')
Condition4 = ''
if Condition4:
print('evaluated to True')
else:
print('evaluated to False')