Operators, Logic, Loops & Refining Code.
10 / 210 DIV 3 (or // )10 MOD 4 (or % )2 ^ 4 (or ** )x = 5, y = 10. True or False?
x > 5 OR y == 10x < 10 AND y != 10NOT (x == 5)average = total / count and average = total DIV count?
/ keeps the decimal value (Float), while DIV removes it (Integer).
score is 100.
(a) =
(b) ==
(c) if score == 100:
(a) OR means only one side needs to be true. 100 is > 13, so it prints "Teenager".
(b) if age >= 13 AND age <= 19:
Runtime Error / TypeError: You cannot concatenate a String with an Integer without casting.
c printed?
Trace Table:
| a | b | c | Output |
|---|---|---|---|
1. a=8, b=3, c=3
2. a=6, b=4, c=7
3. a=4, b=5, c=12
End loop (4 is not > 5)
Output: 12
if (NOT alarm) ______ (keyCard == True ______ masterCode == True)
1. AND
2. OR
if id >= 1 and id <= 3:
print("Red")
elif id >= 4 and id <= 6:
print("Blue")
else:
print("Spectator")
num = int(input("Enter num: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
if num > 0 and num % 10 == 0:
print("Big Ten")
if num < 0:
print("Negative number")
Product has Stock field.
item1's stock by 5.
item1.Stock = item1.Stock - 5