wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

9 Weeks Test

Total questions: 16

Worksheet time: 32mins

Name
Class
Date
1.

What is the primary purpose of the `pickStudent` function?

a)

To select a random student from all three lists

b)

To allow the user to manually pick a student

c)

To randomly select a student from a given list until the user stops

d)

To sort the names in alphabetical order

2.

How does the program determine which class list to use?

a)

It randomly picks one of the three lists

b)

The user inputs a number corresponding to a class

c)

The program assigns a default class

d)

The user types the full name of the class

3.

What will happen if the user enters an invalid input in `pickClass()`?

a)

The program will terminate

b)

The program will ask the user to try again

c)

The program will default to `SIMS3`

d)

The program will print an error message

4.

Which module is used to select a random student?

a)

`math`

b)

`random`

c)

`randomize`

d)

`choice`

5.

What happens when the user types `'end'` in `pickStudent`?

a)

The program terminates immediately

b)

The program stops picking students and returns to `pickClass()`

c)

The program prints "End" and continues

d)

The program ignores the input and continues picking

6.

Why does `pickStudent` use a `while True` loop?

a)

To continuously allow the user to pick students until they type `'end'`

b)

To run the function only once

c)

To prevent errors from invalid input

d)

To avoid calling the function again

7.

Which of the following is a potential issue with the `DINO_BADDIES` list?

a)

The names are not in alphabetical order

b)

The last name entry `'day''drian'` might not be handled correctly

c)

The list contains duplicate names

d)

The list is too short

8.

What is the purpose of `random.choice(class_name)`?

a)

To return a random list from the three available lists

b)

To return a random student name from a given list

c)

To shuffle the class list

d)

To select the last name in the list

9.

How does the program ensure that the user selects a valid class?

a)

By using a `try-except` block

b)

By checking if the input is an integer

c)

By calling `pickClass()` recursively if an invalid input is given

d)

By using a loop to request valid input

10.

What is a possible improvement to avoid infinite recursion in `pickClass()`?

a)

Using a `while` loop instead of recursion

b)

Removing the `else` statement

c)

Changing the input prompt

d)

Using a `break` statement

11.

What is the output if the user types "Python"?

a)

Welcome

b)

Try again!

c)

Error

d)

Enter your password

12.
Which of the following best describes the order in which these lines are processed in Python?
a)
1,2,3,4
b)
1,2,1,2,1,4
c)
1,2,1,2,1,2,4
d)
1,2,1,2,1,2,1,2,4
13.

What is the output

a)
y + x
b)
x + y
c)
3
d)
4
14.

What character should be placed at the end of the function "def" line, after the parentheses?

a)

Hashtag (#)

b)

Colon(:)

c)

Exclamation (!)

d)

Dash (-)

15.

What does the `random.choice()` function do?

a)

Returns a random element from a list

b)

Chooses a random number between 1 and 100

c)

Generates a random choice between True and False

d)

Selects a random key from a dictionary

16.

Which data structure does this describe?

Ordered, changeable, duplicates allowed [ ]

a)

List

b)

Tuple

c)

Set

d)

Dictionary