G08 Revision Notes
G08 Revision Notes
o Selection: Utilizes if, elif, and else statements to execute certain code
based on conditions.
Example:
age = 18
if age < 18:
print("You are a minor.")
elif age == 18:
print("You just became an adult.")
else:
print("You are an adult.")
o Lists are ordered collections that can hold a variety of data types,
including strings.
o Example:
o Example:
x = 10
if x > 5:
print("Greater than five")
else:
print("Not greater than five")
#Predict the output: "Greater than five".
4. Using loops (for, while) to process user input dynamically:
for i in range(5):
print("Iteration", i)
o While loop example:
count = 0
while count < 5:
print("Count is", count)
count += 1
5. Counting items in a list using len():
o Example:
o Identify syntax errors and logical errors by running the code and observing
the output, using print statements or debuggers.
o Example:
o Example:
numbers = [5, 3, 8]
numbers.append(1)
numbers.remove(3)
numbers.sort()
print(numbers)
# Output: [1, 5, 8]
Writing programs that modify lists dynamically: