Variables, Operators, Debugging & Control Flow.
(a) 502
(b) The variables are Strings, so the + operator performs concatenation (joining) instead of addition.
result:
17 MOD 317 DIV 3 (or 17 // 3)2 ^ 3 (or 2 ** 3)(a) A named memory location used to store data that can change while the program is running.
(b) Prevents accidental changes to the value / Makes code easier to update (change in one place).
int(input(...)) - Must cast input to integer.print(...) - Lowercase 'p'.... + str(nextYear) - Cast integer back to string for concatenation.print(currentLevel) cause an error?
(a) currentLevel is a Local variable. It only
exists inside the function.
(b) Harder to debug (track changes) / Waste memory (stay in memory throughout program).
Trace Table:
| x | count | Output |
|---|---|---|
Loop 1: x=3, count=3
Loop 2: x=2, count=5 (3+2)
Loop 3: x=1, count=6 (5+1)
Loop ends (x is not > 1)
Final Output: 6
player1's Score to 500.
RECORD Player
Nickname : String
Score : Integer
IsActive : Boolean
END RECORD
(b) player1.Score = 500
elif / else.
if score > 80:
print("Distinction")
elif score > 60:
print("Merit")
else:
print("Pass")
(b) Once a condition is met, the processor skips the rest. The original code checked ALL statements.
CONST RATE = 1.25
gbp = float(input("Enter GBP: "))
if gbp > 0:
usd = gbp * RATE
print(usd)
else:
print("Invalid amount")