wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Randomness, Libraries, & Debugging

Total questions: 45

Worksheet time: 23mins

Name
Class
Date
1.

Where must this line go in your program?

a)

At the top

b)

In the while loop

c)

After the if-conditionals

d)

At the end

2.

In this line, what is 'random'

a)

random is the name of a library

b)

random is some random number

c)

random is the function that we are running

d)

random is the variable name

3.

What is a 'library' in Python?

a)

A collection of code outside of the program that we can access

b)

A place to get books about programming

c)

The code that makes the import start

d)

The beginning of a program where you write the variables

4.

In this example, which option represents the arguments of the function shown here?

a)

1, 10

b)

randint

c)

random

d)

rand

5.

In this example, which option represents the function shown in this line of code?

a)

randint()

b)

(1, 10)

c)

random

d)

rand

6.

In this example, which option represents the library shown in this line of code?

a)

randint()

b)

(1, 10)

c)

random

d)

rand

7.

In this example, which option represents the variable shown in this line of code?

a)

randint()

b)

(1, 10)

c)

random

d)

rand

8.

Which could be the output of this line of code?

a)

9

b)

-2

c)

6.5

d)

11

9.

How does the computer know to use the random library to run the function in this line?

a)

The dot operator connects the function to the library

b)

The equal sign assigns the function to the library

c)

The arguments tell the function what to do

d)

The variable name tells the computer to look in the random library

10.

Which of the following MUST happen before this line of code tries to run?

a)

The library must be imported

b)

The other variables must be named

c)

The while loop must be started

d)

The lines must be indented

11.

What are these?

a)

Functions

b)

Variables

c)

Data Types

d)

Libraries

12.

Functions are easy to recognize because they always have ___________ after the function name?

a)

parentheses

b)

a colon

c)

a dot operator

d)

quotations

13.

In this example, "Hello" and "Enter name: " are both.....

a)

arguments

b)

variables

c)

functions

d)

the same

14.

What is the data type of age if a user enters 55 into the input field?

a)

string

b)

float

c)

integer

d)

number

15.

If you wanted to get a person's age by using a different prompt than "Enter your age: ", all you have to do is.....

a)

change the argument of the function

b)

change the variable name

c)

use the random library

d)

put int in front of input

16.

In Python, the arguments of a function are always found.....

a)

inside the parentheses after the function name

b)

in the library the function uses to operate

c)

in the variable section of the program

d)

just above the line the function is on

17.

How many arguments does the randint() function require?

a)

2

b)

1

c)

3

d)

0

18.

In which library is the randint() function found?

a)

random

b)

import

c)

rand

d)

argument

19.

After the user enters his or her name, the program will ______ the print function.

a)

call

b)

use

c)

operate

d)

trigger

20.

In this example, the argument used by the function is a(n)....

a)

variable

b)

string

c)

integer

d)

library

21.

What does the input() function do in this program?

a)

Returns a value that is assigned to name

b)

Prints the name of the user

c)

Adds a box on the editor for the user to enter his or her name

d)

Generates a random number

22.

Which of the following is the only one that would work inside the parentheses of this function?

a)

1, 3

b)

"1, 100"

c)

1 25

d)

one, 1000

23.

In Python, which punctuation mark is used as a dot operator?

a)

period

b)

colon

c)

comma

d)

parentheses

24.

Which scenario could the code shown here represent?

a)

Flipping a coin

b)

Playing rock, paper, scissors

c)

Guessing the number of questions on a test

d)

Deciding which kind of cereal to buy

25.

Which would most likely be the next line in this program?

a)

if pick == 1:

b)

if pick = 2:

c)

while pick > 2:

d)

while pick == 0

26.

To show text on your console, your program needs to ______ the print() function.

a)

call

b)

use

c)

trigger

d)

enable

27.

When a Python program runs, a user can type in an answer after the program calls the _____ function.

a)

input

b)

print

c)

rand

d)

entry

28.

If they didn't use libraries, programs like Python would....

a)

require a lot more lines of code

b)

not run very fast

c)

be much easier to write and understand

d)

not work at all

29.

If you ran a program with these lines in it, what would happen?

a)

The program would stop immediately

b)

The program would run up to this line, then it would stop

c)

The program would print "You are the winner"

d)

The program would run forever

30.

A _______ error stops the program right away because Python can’t even understand the instructions well enough to start running them.

a)

syntax

b)

runtime

c)

logic

d)

user

31.

A ______error happens later because the instructions make sense, but something goes wrong while the program is running.

a)

runtime

b)

logic

c)

syntax

d)

user

32.

A program with these lines would stop because of a ______ error when it got to the print function.

a)

runtime

b)

syntax

c)

user

d)

logic

33.

Which would fix the error shown here?

a)

Typecast total into a string

b)

Indent the print line

c)

Put quotes around everything in the parentheses

d)

Import the random library above the first line

34.

Both syntax errors and runtime errors.....

a)

create a message with useful information

b)

tell you exactly how to fix the error

c)

show you exactly which line to fix

d)

allow the program to run until it gets to the error

35.

If your program is not working, what do you need to do?

a)

Debug your program

b)

Write the program all over again

c)

Run the program again

d)

Ask for help

36.

What type of error is shown here?

a)

logic

b)

syntax

c)

runtime

d)

user

37.

How would you know that these lines contain an error?

a)

The program's output would not match what is expected

b)

The program won't run at all

c)

The program will generate an error message

d)

There program wouldn't show the input box

38.

Which type of error is usually the most difficult to find and fix?

a)

logic

b)

syntax

c)

runtime

d)

user

39.

In order to find and fix a logic error, the programmer must....

a)

know what the program is supposed to do when it runs.

b)

read the error message carefuly.

c)

rewrite the program from the beginning.

d)

indent a few lines to see what happens.

40.

The list shown here is best described as ________________ tips.

a)

debugging

b)

programming

c)

coding

d)

evaluating

41.

In this program, which line contains the syntax error?

a)

Line 13 - no colon

b)

Line 14 - not indented enough

c)

Line 9 - misspelled word

d)

Line 14 - incorrect typecasting

42.

In this program, which line contains the runtime error?

a)

Line 13 - no colon

b)

Line 14 - not indented enough

c)

Line 9 - misspelled word

d)

Line 14 - incorrect typecasting

43.

In this program, which line contains the logic error?

a)

Line 10 - incorrect calculation

b)

Line 11 - incorrect calculation

c)

Line 9 - misspelled word

d)

Line 13 - incorrect operator

44.

Why is the misspelled word in line 9 not considered an error?

a)

Because it doesn't affect how the program runs

b)

Because number can also be spelled namber

c)

Because it doesn't stop the program from running

d)

Because it doesn't cause an alert message to pop up

45.

How would you fix the logic error in this program?

a)

Change the 50 in line 10 to 52

b)

Change the multiply sign ' * ' in line 11 to the division sign ' / '

c)

Change the 0 in line 13 to a 1

d)

Change the int in line 9 to str