Python Flashcards
What is an interpreter?
Converts one statement at a time
What is a compiler?
Converts all the statements at once
What is an identifier?
A variable
What are identifier rules?
Must start with a letter or an underscore
The rest can be letters, numbers or underscores
No other characters are permitted
How to create your turtle in Python?
import turtle
leo = turtle.Turtle()
leo.shape(“turtle”)
leo.color(“blue”)
How to move your turtle?
leo.forward(100)
How to move in multiple directions?
leo.left(120) #This rotates the turtle 120 degrees to the left
leo.forward(100)
How to fill an enclosed shape?
leo.fillcolor(“red”)
leo.begin_fill()
#write your turtle code here
leo.end_fill()
Example of an if elif statement?
x = ”cat”
if x == ”dog”:
print(“x is a dog”)
elif x == ”pig”:
print(“x is a pig”)
elif x == ”cat”:
print(“x is a cat”)
else:
print(“x isn’t an animal”)
How to use match statements?
sport = ”basketball”
match sport:
case ”basketball”:
print(“sport is basketball”)
case ”volleyball”:
print(“sport is volleyball”)
case ”rugby”:
print(“sport is rugby”)
case _:
print(“sport is not known”)
How to enter name?
name = str(input(“Please enter your name:”))
How to enter integer?
name = int(input(“Please enter your age:”))
Example of a while statement?
x = 1
while x <=10:
print(x)
x += 1
What is a list?
Instead of
x = 1
y = 2
z = 3
Use
x = [1, 2, 3]
What is range?
Returns a series of outputs. First number is included but not last, eg range(11) would give [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Alternatively, range(1,10) lists numbers 1 to 9. Used in “for” loops