NEW
Font size
WorksheetsRandomness, Libraries, & Debugging
Total questions: 45
Worksheet time: 23mins
Where must this line go in your program?
At the top
In the while loop
After the if-conditionals
At the end
In this line, what is 'random'
random is the name of a library
random is some random number
random is the function that we are running
random is the variable name
What is a 'library' in Python?
A collection of code outside of the program that we can access
A place to get books about programming
The code that makes the import start
The beginning of a program where you write the variables
In this example, which option represents the arguments of the function shown here?
1, 10
randint
random
rand
In this example, which option represents the function shown in this line of code?
randint()
(1, 10)
random
rand
In this example, which option represents the library shown in this line of code?
randint()
(1, 10)
random
rand
In this example, which option represents the variable shown in this line of code?
randint()
(1, 10)
random
rand
Which could be the output of this line of code?
9
-2
6.5
11
How does the computer know to use the random library to run the function in this line?
The dot operator connects the function to the library
The equal sign assigns the function to the library
The arguments tell the function what to do
The variable name tells the computer to look in the random library
Which of the following MUST happen before this line of code tries to run?
The library must be imported
The other variables must be named
The while loop must be started
The lines must be indented
What are these?
Functions
Variables
Data Types
Libraries
Functions are easy to recognize because they always have ___________ after the function name?
parentheses
a colon
a dot operator
quotations
In this example, "Hello" and "Enter name: " are both.....
arguments
variables
functions
the same
What is the data type of age if a user enters 55 into the input field?
string
float
integer
number
If you wanted to get a person's age by using a different prompt than "Enter your age: ", all you have to do is.....
change the argument of the function
change the variable name
use the random library
put int in front of input
In Python, the arguments of a function are always found.....
inside the parentheses after the function name
in the library the function uses to operate
in the variable section of the program
just above the line the function is on
How many arguments does the randint() function require?
2
1
3
0
In which library is the randint() function found?
random
import
rand
argument
After the user enters his or her name, the program will ______ the print function.
call
use
operate
trigger
In this example, the argument used by the function is a(n)....
variable
string
integer
library
What does the input() function do in this program?
Returns a value that is assigned to name
Prints the name of the user
Adds a box on the editor for the user to enter his or her name
Generates a random number
Which of the following is the only one that would work inside the parentheses of this function?
1, 3
"1, 100"
1 25
one, 1000
In Python, which punctuation mark is used as a dot operator?
period
colon
comma
parentheses
Which scenario could the code shown here represent?
Flipping a coin
Playing rock, paper, scissors
Guessing the number of questions on a test
Deciding which kind of cereal to buy
Which would most likely be the next line in this program?
if pick == 1:
if pick = 2:
while pick > 2:
while pick == 0
To show text on your console, your program needs to ______ the print() function.
call
use
trigger
enable
When a Python program runs, a user can type in an answer after the program calls the _____ function.
input
rand
entry
If they didn't use libraries, programs like Python would....
require a lot more lines of code
not run very fast
be much easier to write and understand
not work at all
If you ran a program with these lines in it, what would happen?
The program would stop immediately
The program would run up to this line, then it would stop
The program would print "You are the winner"
The program would run forever
A _______ error stops the program right away because Python can’t even understand the instructions well enough to start running them.
syntax
runtime
logic
user
A ______error happens later because the instructions make sense, but something goes wrong while the program is running.
runtime
logic
syntax
user
A program with these lines would stop because of a ______ error when it got to the print function.
runtime
syntax
user
logic
Which would fix the error shown here?
Typecast total into a string
Indent the print line
Put quotes around everything in the parentheses
Import the random library above the first line
Both syntax errors and runtime errors.....
create a message with useful information
tell you exactly how to fix the error
show you exactly which line to fix
allow the program to run until it gets to the error
If your program is not working, what do you need to do?
Debug your program
Write the program all over again
Run the program again
Ask for help
What type of error is shown here?
logic
syntax
runtime
user
How would you know that these lines contain an error?
The program's output would not match what is expected
The program won't run at all
The program will generate an error message
There program wouldn't show the input box
Which type of error is usually the most difficult to find and fix?
logic
syntax
runtime
user
In order to find and fix a logic error, the programmer must....
know what the program is supposed to do when it runs.
read the error message carefuly.
rewrite the program from the beginning.
indent a few lines to see what happens.
The list shown here is best described as ________________ tips.
debugging
programming
coding
evaluating
In this program, which line contains the syntax error?
Line 13 - no colon
Line 14 - not indented enough
Line 9 - misspelled word
Line 14 - incorrect typecasting
In this program, which line contains the runtime error?
Line 13 - no colon
Line 14 - not indented enough
Line 9 - misspelled word
Line 14 - incorrect typecasting
In this program, which line contains the logic error?
Line 10 - incorrect calculation
Line 11 - incorrect calculation
Line 9 - misspelled word
Line 13 - incorrect operator
Why is the misspelled word in line 9 not considered an error?
Because it doesn't affect how the program runs
Because number can also be spelled namber
Because it doesn't stop the program from running
Because it doesn't cause an alert message to pop up
How would you fix the logic error in this program?
Change the 50 in line 10 to 52
Change the multiply sign ' * ' in line 11 to the division sign ' / '
Change the 0 in line 13 to a 1
Change the int in line 9 to str
