Menu

Using Subroutines

Card 1 of 18 0 got it 0 still learning
Question
TapClick or press space to see the answer
Answer
All 18 cards in this set
Which term describes a named block of code that can be run whenever it is needed?
A subroutine
Which keyword is written at the start of a subroutine definition?
Def
What is meant by calling a subroutine?
Writing the name of the subroutine with brackets so the code inside it runs
Which term describes the pair of round symbols that must be written after a subroutine name at the end of the def line and again each time it is called?
Brackets
What is meant by defining a subroutine?
Writing a def line and the code that belongs to it
Which symbol must come at the end of the def line, after the brackets?
A colon
In the line def draw_star():, what is the name of the subroutine?
draw_star
Which line correctly starts the definition of a subroutine called draw_square?
Def draw_square():
Why is a subroutine useful when a program draws the same shape many times?
It removes repeated code and keeps the program short
A student defines a subroutine that draws a square, then runs the whole program. Nothing is drawn. What is the most likely reason?
The subroutine was defined but never called
A subroutine called draw_circle has already been defined. Which line calls it?
draw_circle()
How many times can a subroutine be called in a program?
As many times as needed, and it runs the same way each time
Why does the code inside a subroutine need to be indented?
It shows Python which lines belong to the subroutine
A subroutine called square contains a for loop that draws one square. What happens when square() is called three times?
Three squares are drawn, one from each call
A subroutine draws a square. A student wants to draw two squares in different places. What must be added between the two calls?
Lift the pen, move the turtle, then put the pen down again
A program defines draw_square(), and later has the line draw_square with no brackets. What happens when the program runs?
The subroutine is not called, so no square is drawn
A subroutine draw_square() draws one square. A student wants to draw four squares in a row. What is the best way to do this without repeating the square code?
Call draw_square() in a loop four times
What happens if the lines of code inside a subroutine are not indented?
They are not part of the subroutine