Python Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is an interpreter?

A

Converts one statement at a time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a compiler?

A

Converts all the statements at once

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an identifier?

A

A variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are identifier rules?

A

Must start with a letter or an underscore
The rest can be letters, numbers or underscores
No other characters are permitted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to create your turtle in Python?

A

import turtle

leo = turtle.Turtle()
leo.shape(“turtle”)
leo.color(“blue”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to move your turtle?

A

leo.forward(100)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to move in multiple directions?

A

leo.left(120) #This rotates the turtle 120 degrees to the left
leo.forward(100)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to fill an enclosed shape?

A

leo.fillcolor(“red”)
leo.begin_fill()
#write your turtle code here
leo.end_fill()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Example of an if elif statement?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to use match statements?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to enter name?

A

name = str(input(“Please enter your name:”))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to enter integer?

A

name = int(input(“Please enter your age:”))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Example of a while statement?

A

x = 1
while x <=10:
print(x)
x += 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a list?

A

Instead of
x = 1
y = 2
z = 3
Use
x = [1, 2, 3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is range?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Example of a “for” loop?

A

for x in range (1,6):
print(x)

17
Q

How to put text in “for” loops?

A

for x in [‘cat’, ‘dog’, ‘horse’]:
print(x)

18
Q

How to put a loop in a loop?

A

for num1 in range (1, 11):
for num2 in range (1, 11):
print(num1, “ + “, num2, “ = “,
num1 + num2)

19
Q

Using ‘for’ loops in turtle?

A

for x in range (4):
leo.forward(200)
leo.left(90)

20
Q

Using “while” loops in turtle?

A

x = 0
while (x < 3):
leo.forward(150)
leo.left(120)

21
Q

How to change Turtle width, change turtle colour and background colour?

A

turtle.color(“yellow”)
turtle.bgcolor(“black”)
turtle.width(“12”)

22
Q

Circle in turtle?

A

leo.circle(150)

23
Q

Functions?

A

def welcome_player():
name = input(“Enter a username: “) …

After all your code is done, call upon the function, like
welcome_player()

24
Q

How to return a certain letter of a certain word?

A

def print2(value):
print(value[1])
print2(“Superman”)

This will return “u”

25
Q

Slicing?

A

x = “Superman”
print(x[2:5])

Would return the string per

26
Q

Length of string?

A

len(“Fichy”)

would return “5”

27
Q

How to slice from the start?

A

X = “MrFich”
print(x[2:])

This would return “Fich”

28
Q

How to slice from the back?

A

x = “MrFich”
print(x[-2:])

This would return “ch”

29
Q

How to remove the start and end?

A

return str[1:len(str)-1]

30
Q

What is a list and how do you access a value of the list?

A

myList = [“Alpaca”, “Badger”, “Cat”, “Dog”]
Use myList[0] to get Alpaca
Use myList[-1] to get Dog

31
Q

How to use len() in a list?

A

len(myList)