You are on page 1of 6

Revision Sheet

Python is a text-based programming language that anyone can


download and install at no charge.
A variable is a storage location in the memory that can store values or
information.
A variable can be filled through 3 ways:
1. The input command ex: age = input(“type your age”)
2. Simple assignment x=9
3. Mathematical calculation ex: a=b+3
Rules to name a variable:
1. A variable can be a combination of letters and numbers; however
it must start with a letter.
2. Special characters are not allowed only underscore _.
3. Reserved commands like print() elif and input() cannot be used as
variable name.
4. If the variable is composed of two words, separate with
underscore. Spaces are not allowed ex: my age > my_age.
Loops like for and while are used to repeat instructions. A counter is
used in the while loop to break out of the loop when the condition
becomes false.
Any input by the user is considered as a string.
Input is an instruction used to ask the user to type information from the
keyboard.
Print is an instruction used to display results on the screen to the user.
While using the print instruction, anything between quotes “” will be
considered as string. Everything else outside the quotes “” is either a
variable or a calculation.
Ex: print(“100+90”) will display 100+90 as a string
Print (55+40) will display 95 an actual calculation
Int is used to change the user input from string to integer.
Float is used to change the user input from string to a decimal number.
Round is used to round the number to the nearest whole number.
A conditional statement will enable the computer to make a decision based
on a specific rule.
If is a conditional statement that evaluates a condition.
elif is used when we have more than two condition nested together.
If, elif, and else statements always end with a colon (:).
!= is a comparison sign that means “not equal to”.
If, elif, else

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

round +=1 is the same as


round = round +1
Embedded loops definition
There are two while loop in the example

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

The math library

The turtle library


Turtle.forward(10) will move the turtle 10 steps forward.
Turtle.backward(10) will move the turtle 10 steps backward.
Turtle.right(60) will turn the turtle 60 degrees to the right.
Turtle.left(60) will turn the turtle 60 degrees to the left.
Turtle.pendown() will put the pen down to draw.
Turtle.penup() will put the pen up to stop drawing.
Turtle.penwidth(6) will change the thickness of the pen.
Turtle.color(‘green’) will change the color of the pen.
Revision sheets are only supplementary and should not replace studying from the
textbook.

You might also like