WorksheetsTynker Python Lesson 7-8
Total questions: 84
Worksheet time: 42mins
You need to import the turtle module before you can use the Turtle Tool.
True
False
When you first create a turtle, it starts at (0,0) on the screen. Where will the turtle be if we execute the following code?
turtle.forward(100)
(0,0)
(100,0)
(0,100)
(100,100)
When you first create a turtle, it starts at (0,0) on the screen. Where will the turtle be if we execute the following code?
turtle.right(90)
turtle.forward(100)
(100,0)
(0,-100)
(100,-100)
(100,-100)
When you first create a turtle, it starts at (0,0) on the screen. Where will the turtle be if we execute the following code?
turtle.right(90)
turtle.goto(100,100)
(0,-100)
(0,0)
(100,100)
(200,0)
What function do you use to get the turtle to start drawing?
turtle.penup()
turtle.pendown()
turtle.goto()
turtle.right()
What function do you use to create a new Turtle object?
turtle.Screen()
turtle.Turtle()
turtle.penup()
turtle.goto()
Which of the following code sets the screen's color to red?
screen.color("red")
screen.make("red")
screen.hide("red")
screen.bgcolor("red")
True or False : You can only have one Turtle on the screen.
True
False
An identifier cannot begin with a number. Which of the following is NOT a valid identifier?
num
_num
NUM
1num_
An identifier can begin with an underscore (“_”).
True
False
An identifier can begin with a number.
True
False
In Python, an identifier may begin with an underscore or a letter. Which of the following is a valid identifier? Select all that apply.
_total
2_count
NUM_COUNT
dollar_sign
Which of the following is a valid function call?
forwad)
tu-left()
forward()
forward(;
Select the following function calls that are invalid.
ford)(
$forDS()
forward()
turn_left()
How would you call a function named “my_function”?
Call my_function()
my_function
my_function))
my_function()
Identifiers in Python are case-sensitive.
True
False
78090 is a valid identifier in Python.
True
False
Select the following invalid identifiers. (Identifiers are only allowed to start with an underscore or letter.)
&ident
1ident
_ident
-ident
How would you move an object forward 3 times?
forward() forward() forward()
forward() * 3
Call_forward() 3 times
forward() {3}
You are not able to call the same function twice in a row.
True
False
You can replace the parentheses on a function call with square brackets.
True
False
The parentheses at the end of a function call are optional.
True
False
'''Which of the following is the correct way to start a multi-line comment?
'''
/*
#
//
Both of the following are valid ways to comment code:
Both of the following are valid ways to comment code:
# hello
# world
' ' 'hello world' ' '
True
False
Which of the following comments are correct? Select all that apply.
// hello
# hello
/*he
llo */
//he
llo//
Commented lines affect the execution of your program.
True
False
What is the error in this code?
What is the error in this code?
''' This function does something '''
def foo() :
print("hello world") ''' prin
The single line comment must use # instead of '''
The end of the multi-line comment cannot be on its own line
The beginning and end of the multi line comments are incorrect
All answers are errors in the code
How many blocks will the character move using the following code?
for i in range(1,5) :
forward()
3
4
5
6
Which "for" loop will move your character 5 times?
for i in range(1,5) : forward()
for i in range(5) : forward()
for i in range(1,3) : forward()
for i in range(2,5) : forward()
The following "for" loop has correct syntax.
for rang(1,1) :
forward()
True
False
How many times will “function1” be called?
for i in range(10) :
for j in range(10) :
function1()
25
20
50
100
Which is the correct syntax to make a "for" loop run for all numbers from 0 to 10?
for i in range(1,10) :
for i in range(10) :
for i in range(-10) :
for i in range(11) :
The following loop will go from i = 5 to i = 1.
for i in range(5,0,-1)
True
False
"For" loops can increment upwards or downwards.
True
False
Choose the following "for" loops that repeat 5 times. Mark all that apply.
for i in range(5)
for i in range(1,5)
for i in range(5,10)
for i in range(10,2)
Select the invalid "for" loops.
for i in range(5) :
for 2 in range(5) :
for i in range() :
for i in range(5,-1) :
How many times will the following "for" loop execute?
for i in range(10,5,-1) :
20
10
5
0
Why should you indent your code?
In Python, the program’s execution changes based on whether you indent or not
Code that is not indented properly will produce syntax errors
It is much easier to read indented code
All of the above
Which of the following makes the character shoot if there is an enemy ahead? Mark all that apply.
if enemy_in_sight() : long_jump()
if not enemy_in_sight() : fire()
if enemy_in_sight() : fire()
if enemy_in_sight() : forward()
The following two pieces of code do the same thing:
if condition :
forward()
# next code
if condition :
forward()
else :
fire()
True
False
You are given three variables, A=True, B=False and C=False. What is the value of the expression A and ( B or C )?
True
False
None
I don't know
Which part of a conditional goes after the if keyword and before the colon?
The word “if”
The word “else”
The code to run
The condition
When would you use an "if-else" statement over an "if" statement?
When you want to stop running code once the condition is false
When you want to run different code if a condition is false
When you want to run code and then check if the condition is true after
They have the exact same function
There is no difference between an "if" statement and an "if-else" statement.
True
False
If you wanted to run different code given different conditions, how would you do that?
Combine all the conditions in one condition using “or”
Use “elif” statements
Put everything in the “else” statement
Create two functions
When running this code, what will the character do if there is an enemy?
if not enemy_in_sight() :
fire()
fire
nothing
walk forward
jump
What would the following code do?
while True :
print(“Hello”)
Print “Hello” once
Print “Hello” infinitely
Do nothing
None of the above
"While" loops always terminate eventually.
True
False
What is the output of this code?
i = 1
while (i < 1) :
print(“hello”)
hello
hello
hello
It will output an error
It won't output anything
When might you use a "while" loop instead of a "for" loop?
If you know exactly how many iterations you want to perform
If you don’t know exactly how many iterations you want to perform
You should always use a "while" loop instead of a "for" loop
You should never use a "while" loop instead of a "for" loop
What is outputted by this code?
while True : break print("Hello") else : print("World")
Hello
Hello
World
It will not output anything
World
