-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathIP_PYTHON_PROGRAMMING_CLASS_NOTES_9
More file actions
127 lines (96 loc) · 3.58 KB
/
Copy pathIP_PYTHON_PROGRAMMING_CLASS_NOTES_9
File metadata and controls
127 lines (96 loc) · 3.58 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
INTERNATIONAL PASSPORT: PYTHON PROGRAMMING
CLASSNOTES & HOMEWORK ASSIGNMENT:
CLASS - June 25, 2023 - SUNDAY - CLASS 9 @6:30PM EST
CONDITIONAL LOGIC
⁃ When you get into running more complex code, at some point you are going to need to be able to say when this happens, do this. When something else happens, react differently.
⁃ This is why you need to handle conditions inside of your code and why if and else statements are important.
IF AND ELSE STATEMENTS
⁃ The if-else statements is used to execute both the true part and the false part of a given condition. If the condition is true, the if block code is executed and if the condition is false, the else block code is executed.
ELSE STATEMENT
⁃ If the “if statement” is not true, this where the else statement comes in handy
⁃ The statement catches anything which isn’t caught by the preceding conditions.
ELIF STATEMENT
⁃ Elif is short for else if and is used when the first if condition is not true, but you want to check for another condition. So, if you elif condition is true, the elif condition therefore be printed out.
OPERATORS
⁃ Operators are used to perform operations on variables and values in python.
⁃ Example operators are + (addition), - (subtraction) etc.
⁃ For the context of this class we will be focusing on the and, or and not operators.
⁃ And - will return true to you if both the statements are true. It is used to combine conditional statements.
⁃ Or - returns true if one of the statements are true. This is also used to combine conditional statements.
⁃ Not - will return false if the results is true.
CONDITIONAL LOGIC TEMPLATE
⁃ Python supports the usual logical conditions from mathematics
⁃ > Great than
⁃ < Less than
⁃ >= greater than or equal to
⁃ <= less than or equal to
For more information on CONDITIONAL PYTHON LOGIC, please visit:
https://www.w3schools.com/python/python_conditions.asp
# LAB 1 - IF STATEMENT EXAMPLE
c = 50
d = 400
if d > c:
print("D is greater than C")
# LAB 2 - IF STATEMENT COMPLEX EXAMPLE
price = input("How Much Did You Pay? ")
price = int(price)
if price >= 100:
tax = .07
print(" Your tax rate is: " +str(tax))
# LAB 3 - ELSE STATEMENT EXAMPLE
c = 400
d = 50
if d > c:
print("D is greater than C")
else:
print("C is greater than D")
# LAB 4 ESLE STATEMENT COMPLEX EXAMPLE
price = input("How Much Did You Pay? ")
price = int(price)
if price >= 100:
tax = .07
print("Tax rate is: "+ str(tax))
else:
tax = 0
print("Tax rate is: "+ str(tax))
# LAB 5 ELIF STATEMENT EXAMPLE
c = 50
d = 50
if d > c:
print("D is greater than C")
elif c == d:
print("C and D are equal")
# LAB 6 - BRINGING IF, ELIF AND ELSE ALTOGETHER
c = 51
d = 50
if d > c:
print("D is greater than C")
elif c == d:
print("C and D are equal")
else:
print("C is greater than D")
# LAB 7 - AND OPERATOR LAB
k = 500
z = 200
i = 800
if i > k and i > z:
print("Both conditions are true!")
# LAB 8 - OR OPERATOR LAB
k = 500
z = 200
i = 800
if i > k or z > i:
print("One of the conditions is indeed true!")
# LAB 9 - NOT OPERATOR LAB
k = 500
z = 200
i = 800
if not k > i:
print("It appears K is not greater than I")
________________________________________________________________________
HOMEWORK:
⁃ Add to your python journal documenting you work.
⁃ Write 2 different examples of each lab per subject e.g. if, else, elif, and, or, not
⁃ You must send International Passport (IP) all your homework by Saturday 11:59 PM EST
⁃ Send to my email: matthewstravels85@gmail.com
________________________________________________________________________