wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Section 1: Building a Simple Chatbot

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Consider this Python chatbot snippet: import time; print("Hi! I'm ChatBuddy, your friendly chatbot!"); time.sleep(1). What is the primary purpose of calling time.sleep(1) in this context?

a)

To print text in bold

b)

To pause the program for approximately one second

c)

To convert user input to lowercase

d)

To repeat the greeting twice

2.

In the line name = input("What's your name? "), which best describes what the variable name stores after this code runs?

a)

A number representing the user's age

b)

A Boolean indicating if the user typed something

c)

A string containing the user's typed response

d)

A list of all previous responses

3.

The code collects a mood using mood = input("How are you feeling today? (good/bad) ").lower(). Why is .lower() applied here?

a)

To remove spaces from the input

b)

To ensure the input is treated as a number

c)

To standardize the input to lowercase for reliable if/else comparison

d)

To automatically translate the input to English

4.

Given the following conditional: if mood == "good": print("That's awesome! Keep smiling ") else: print("Oh no! I hope your day gets better soon "), which user input will trigger the else branch when .lower() is used?

a)

good

b)

GOOD

c)

GoOd

d)

bad

5.

You are asked to add a new question about favourite food and make the bot respond differently if the user says 'pizza'. Which approach best uses if/else logic to meet this requirement?

a)

Ask for food and always print the same message regardless of input

b)

Ask for food and use if food == "pizza": to print a special message; otherwise print a general response

c)

Convert food to an integer and compare numbers

d)

Use time.sleep() to choose the response randomly

6.

The bot prints: print("Cool! I wish I could do " + hobby + " too!"). Which concept does this line illustrate?

a)

List indexing to access items

b)

String concatenation using variables and literals

c)

Arithmetic addition of numbers

d)

Importing external libraries

7.

Which Python statement selects a random element from a list of possible chatbot replies stored in the variable answers?

a)

print(answers[0])

b)

random.choice(answers)

c)

answers.random()

d)

choice.random(answers)

8.

In the snippet: answers = ["Yes!", "No!", "Maybe...", "Ask again later."] — what Python data structure is being used to hold multiple possible responses?

a)

Dictionary

b)

Tuple

c)

List (array)

d)

Set

9.

A Magic 8-Ball chatbot waits briefly before replying. Based on the example, which pair of lines creates this delay?

a)

print("Thinking...") followed by random.choice(answers)

b)

time.sleep(1) and time.sleep(2)

c)

import random and import time

d)

question = input("Ask your question: ") and print("Welcome to the Magic 8-Ball!")

10.

You want your chatbot to be less predictable while keeping a fixed set of possible answers. Which approach best achieves this, according to the lesson?

a)

Append new answers to the list after each question so it never repeats

b)

Shuffle the list once at startup and always use the first item

c)

Use random.choice() to select a response from a predefined list

d)

Sort the list alphabetically and print the middle element

11.

A business wants a playful Q&A widget similar to a Magic 8-Ball. Which minimal sequence of steps mirrors the example to produce a randomized reply?

a)

Create a list of answers, import random, and call random.choice() on that list

b)

Import time, print a welcome message, and ask for input without using random

c)

Store answers in a single string, then slice a random character

d)

Use a dictionary of answers keyed by numbers and always return key 1

12.

In the provided Tech Helper 3000 chatbot snippet, which Python statement selects a random response from a list based on the user’s problem category?

a)

time.sleep(1)

b)

random.choice(wifi_responses)

c)

input("What problem are you having?")

d)

print("Welcome to Tech Helper 3000!")

13.

The chatbot asks the user to enter "wifi/sound/other" and then applies conditional logic. Which control structure correctly routes to the matching response list?

a)

for loop with range over responses

b)

try/except around input

c)

if problem == "wifi"; elif problem == "sound"; else

d)

while loop until valid input

14.

You want to add a new category "battery" with its own random tips without breaking existing behavior. Which approach best applies the concept of conditional random selection?

a)

Append "battery" tips to wifi_responses so they are reused

b)

Replace the else block with print(random.choice(battery_responses))

c)

Create battery_responses list and add an elif problem == "battery" that prints random.choice(battery_responses)

d)

Put all tips into one mixed list and always print random.choice(all_tips)

15.

In planning a customer support chatbot for a business, why combine random.choice with if/elif/else as shown in Tech Helper 3000?

a)

It guarantees the same tip appears every time for consistency

b)

It enables varied replies tailored to each problem type, improving user engagement

c)

It prevents the need to store lists of responses in variables

d)

It replaces the need for collecting user input entirely