G9 - Revision Sheet Python
G9 - Revision Sheet Python
The script first takes the user's age as input and convert it to integer.
- It then checks three conditions using `if`, `elif` (else if), and `else` statements.
- If the age is 64 or older, it prints a message to renew the driving license.
- If the age is between 18 and 63 (inclusive), it prints a message indicating that the
person can drive a car.
- If the age is below 18, it prints a message stating that the person can't drive a car.
Note that instructions under if, elif and else are indented.
The code is a basic example of conditional statements in Python, used to make
decisions based on different age ranges.
The following example works the same way based on the av result will display the
right message.
For loops
For loop needs three parameters: the starting value, the ending value, and the step
(how many numbers to skip each iteration)
Remember that the ending value is not included in the number of rounds.
`for` loop example:
While loops
The while loop like the ‘for’ loop repeats instructions as long as the condition is true.
Once the condition becomes false the loop stops. However, the while loop needs a
counter to control the number of repetitions. Counter is the like the step value in for
loop and will decide how many numbers to skip ex: counter=counter+2
The outer loop runs 3 times, and the inner loop runs 4 times:
1 1, 1 2, 1 3, 1 4, 2 1, 2 2, 2 3, 2 4, 3 1, 3 2, 3 3, 3 4