Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Basic Programming Concepts Quiz

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Which line of code correctly stores a player's score of 100 in a variable?

a)

100 = playerScore

b)

playerScore: 100

c)

playerScore = 100

d)

playerScore = "100"

2.

What is the main purpose of an if statement?

a)

To repeat a block of code multiple times.

b)

To make a decision and run code only if a condition is true.

c)

To store a list of items.

d)

To get input from a user.

3.

A player has health = 10. Which if statement correctly checks if the player has run out of health?

a)

if health = 0:

b)

if health > 0:

c)

if health == 0:

d)

if health is 0:

4.

What will this code print? player_age = 13 if player_age >= 13: print("Welcome, teen!") else: print("You are too young.")

a)

You are too young.

b)

Welcome, teen!

c)

It will print nothing.

d)

It will cause an error.

5.

Which line of code correctly asks the user for their name and stores it in the user_name variable?

a)

"what is your name?" = user_name

b)

user_name = input("What is your name? ")

c)

input(user_name)

d)

user_name = "What is your name? "

6.

What is a for loop best used for?

a)

Running code forever until the program crashes.

b)

Running code as long as a condition is true.

c)

Iterating over a sequence (like a list) a known number of times.

d)

Making a single decision.

7.

What will be printed by the following loop? Python for i in range(3): print("Ahoy!")

a)

Ahoy!

b)

Ahoy!

Ahoy!

c)

Ahoy!

Ahoy!

Ahoy!

d)

Ahoy!

Ahoy!

Ahoy!

Ahoy!

8.

You want to create a countdown from 5 to 1. Which while loop is set up correctly?

a)

count = 5

while count > 5: print(count)

b)

count = 5

while count < 0: print(count);

count = count - 1

c)

count = 5

while count > 0: print(count);

count = count - 1

d)

count = 0

while count < 5: print(count);

count = count + 1

9.

What is an "infinite loop"?

a)

A loop that runs exactly 1,000,000 times.

b)

A for loop that has too many items in its list.

c)

A loop where the condition to stop it is never met.

d)

A loop that contains an error.

10.

How would you print each item from the inventory list on a new line? inventory = ["sword", "shield", "potion"]

a)

print(inventory)

b)

while item in inventory: print(item)

c)

for item in inventory: print(item)

d)

for inventory:

print(item)

11.

How would you get a random baddie from the list: baddie = ["Goblin", "Slime", "Wolf", "Bandit"]?

a)

baddie[3]

b)

baddie.random()

c)

import random;

random.choice(baddie)

d)

random(baddie)

12.

Which line of code adds a "gold coin" to a player's inventory = ["torch", "rope"]?

a)

inventory.add("gold coin")

b)

inventory + "gold coin"

c)

inventory.append("gold coin")

d)

inventory[2] = "gold coin"

13.

Which is the best way to store a path for a story with three choices: choice1 = "Go left"; choice2 = "Go right"; choice3 = "Go straight"?

a)

choices = ["Go left", "Go right", "Go straight"]

b)

choices = "Go left, Go right, go straight"

c)

choices = {1:"Go left", 2:"Go right", 3:"Go straight"}

d)

choices = (1:"Go left", 2:"Go right", 3:"Go straight")

14.

Which line of code removes "Heal" from the list of spells: spells = ["Fireball", "Heal", "Ice Bolt"]?

a)

spells.delete("Heal")

b)

spells.remove("Heal")

c)

spells - "Heal"

d)

spells[1].remove()

15.

What will be the result of the code shown?

a)

7

6

5

4

3

2

1

b)

7

6

5

4

3

2

c)

7

6

5

4

3

d)

Nothing, there's an error