NEW
Font size
WorksheetsSection 1: Building a Simple Chatbot
Total questions: 15
Worksheet time: 8mins
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?
To print text in bold
To pause the program for approximately one second
To convert user input to lowercase
To repeat the greeting twice
In the line name = input("What's your name? "), which best describes what the variable name stores after this code runs?
A number representing the user's age
A Boolean indicating if the user typed something
A string containing the user's typed response
A list of all previous responses
The code collects a mood using mood = input("How are you feeling today? (good/bad) ").lower(). Why is .lower() applied here?
To remove spaces from the input
To ensure the input is treated as a number
To standardize the input to lowercase for reliable if/else comparison
To automatically translate the input to English
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?
good
GOOD
GoOd
bad
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?
Ask for food and always print the same message regardless of input
Ask for food and use if food == "pizza": to print a special message; otherwise print a general response
Convert food to an integer and compare numbers
Use time.sleep() to choose the response randomly
The bot prints: print("Cool! I wish I could do " + hobby + " too!"). Which concept does this line illustrate?
List indexing to access items
String concatenation using variables and literals
Arithmetic addition of numbers
Importing external libraries
Which Python statement selects a random element from a list of possible chatbot replies stored in the variable answers?
print(answers[0])
random.choice(answers)
answers.random()
choice.random(answers)
In the snippet: answers = ["Yes!", "No!", "Maybe...", "Ask again later."] — what Python data structure is being used to hold multiple possible responses?
Dictionary
Tuple
List (array)
Set
A Magic 8-Ball chatbot waits briefly before replying. Based on the example, which pair of lines creates this delay?
print("Thinking...") followed by random.choice(answers)
time.sleep(1) and time.sleep(2)
import random and import time
question = input("Ask your question: ") and print("Welcome to the Magic 8-Ball!")
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?
Append new answers to the list after each question so it never repeats
Shuffle the list once at startup and always use the first item
Use random.choice() to select a response from a predefined list
Sort the list alphabetically and print the middle element
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?
Create a list of answers, import random, and call random.choice() on that list
Import time, print a welcome message, and ask for input without using random
Store answers in a single string, then slice a random character
Use a dictionary of answers keyed by numbers and always return key 1
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?
time.sleep(1)
random.choice(wifi_responses)
input("What problem are you having?")
print("Welcome to Tech Helper 3000!")
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?
for loop with range over responses
try/except around input
if problem == "wifi"; elif problem == "sound"; else
while loop until valid input
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?
Append "battery" tips to wifi_responses so they are reused
Replace the else block with print(random.choice(battery_responses))
Create battery_responses list and add an elif problem == "battery" that prints random.choice(battery_responses)
Put all tips into one mixed list and always print random.choice(all_tips)
In planning a customer support chatbot for a business, why combine random.choice with if/elif/else as shown in Tech Helper 3000?
It guarantees the same tip appears every time for consistency
It enables varied replies tailored to each problem type, improving user engagement
It prevents the need to store lists of responses in variables
It replaces the need for collecting user input entirely
