Python - How to think like a computer scientist Flashcards
What is a “state snapshot”?
A more popular word (“most often referred to”) for reference diagram that maps variable names and values they refer to at a particular point in time
Compare the error types between JavaScript and Python
What does the line “import turtle” do?
load turtle module and associated types/objects (e.g. Turtle(), screen()
define: instances. how do we create instances
copy of an object, independent of each other and has their own properties and methods
alex = turtle.Turtle()
tess = turtle.Turtle()
give an example of a for loop and identify the different parts
example:
for i in [item1, item 2, item3]: print(i)
LOOP VARIABLE: i
LIST: [item1, item 2, item3]
LOOP BODY: print(i)
define control flow
python keeping track of the code statement it’s executing, like a pointer finger
what is a sequential control flow?
execution of code from top to bottom
explain in flow chart how the for loop is a sequential control flow
what’s another name for control flow
flow of execution
how is the for
loop a compound statement?
indentation
what’s the general structure to print a range of numbers in an iteration?
range(start, stop, step)
why do we need to wrap range in a list?
list(range()) - apparently range sometimes doesn’t print all the values
what values would these statements give?
print(list(range(4)))
print(list(range(1, 5)))
print(list(range(1, 5, 2)))
[0, 1, 2, 3]
[1, 2, 3, 4]
[1, 3]
identify method that allows us to turn a turtle negative angles or distances
turning a number negative produces the opposite of a specified direction
e.g. Turtle.forward(-100) moves it backward by 100
but you can also write this as Turtle.backward(100)
identify method that allows turtle to pickup or put down pen
Turtle.up() / Turtle.penup()
Turtle.down() / Turtle.pendown()
identify method that influences turtle shape, some shapes the turtle can take on
Turtle.shape(“”)
shapes = classic (pointer - think this is also the default), turtle, square, triangle, etc
identify method that influences turtle’s animation speed
Turtle.speed()
identify method to leave an imprint of the turtle shape on canvas
Turtle.stamp()
what is programming?
“breaking up large task into tinier tasks that are generally made up of basic instructions”
programs vs algorithms?
algorithm is a set of instructions but doesn’t necessarily need to be written in a language for the computer to interpret
a program is a set of instructions that needs to be more precise so the computer can follow