EXERCISE 5: Customise feedback messages with if statements

Task: Use if and elif statements to display a feedback message based on performance after the progress and score summary you created in the exercise above. Before implementing, start by deciding on some score thresholds for which different messages should be displayed. E.g.

  • above 90%: “Excellent work!”
  • 70-90%: “Good job!”
  • 50-70%: “Keep practicing!”
  • 50% or lower: “Need more study time!” You should use logical operators and comparator operations to test for the different score ranges. Then use if and elif statements to display a feedback message based on performance after the progress and score summary you created in the exercise above.

Bonus Task: Can you think of further checks you might do on the score? The code assumes the value would lie between 0 and 100, but perhaps you should do something to flag cases where it lies outside this range, e.g. what should be the behaviour if the score_percentage is 250 or -24?

Run and check: Run your code in the terminal to make sure it works with the command

python flashcards_app.py

In the same way as you did for the previous task, test your code by setting your variables to different values to check you get the messages your expect. E.g. what do you expect the message to be when:

  • num_cards_completed = 3 and num_cards_correct = 2?
  • num_cards_completed = 5 and num_cards_correct = 0?
  • num_cards_completed = 10 and num_cards_correct = 5? If you don’t get what you expect, check your code and try to find out why.

Read through and add comments: Add any comments in your code that will help you understand it when you come back to it later.

Save your progress: Commit with a descriptive message, e.g. “EXERCISE 5: Customise feedback messages with if statements” and save your work to Github with the standard Git workflow.

(Re)read the guides:

Example solution

flashcards_app.py

# Created by: Alex Ubuntu
# Date: 01.01.2026
# Purpose: A personal flashcard trainer to help with learning

# Card and score variables - set to arbitrary values for testing purposes
num_cards_completed = 10
num_cards_correct = 5
score = (num_cards_correct/num_cards_completed) * 100

# Welcome message
print("Welcome to your personal flashcard trainer!")

# Fetch from user and save to variable
name = input("What is your name? ")

# Confirm name
print(f"My name is {name}")

# Fetch from user and save to variable
max_cards = int(input("How many cards would you like to practice each session? "))

# Confirm number maximum number of cards per session
print(f"I want to practice at most {max_cards} cards per session")

# Display score information
print(f"You have answered {num_cards_correct} out of {num_cards_completed} correctly. Your score so far is {score}%.")

# Display feedback message based on score
if score > 90:
    print("Excellent work!")
elif score > 70 and score <= 90:
    print("Good job!")
elif score > 50 and score <= 70:
    print("Keep practicing!")
else: 
    print("Need more study time!") # assumes score variable behaves
    

With more stringent checks for the score (Bonus Task)

# Created by: Alex Ubuntu
# Date: 01.01.2026
# Purpose: A personal flashcard trainer to help with learning

# Welcome message
print("Welcome to your personal flashcard trainer!")

# Fetch from user and save to variable
name = input("What is your name? ")

# Confirm name
print(f"My name is {name}")

# Fetch from user and save to variable
max_cards = int(input("How many cards would you like to practice each session? "))

# Confirm number maximum number of cards per session
print(f"I want to practice at most {max_cards} cards per session")

# Card and score variables
num_cards_completed = 10
num_cards_correct = 5
score = (num_cards_correct/num_cards_completed) * 100

# Display score information
print(f"You have answered {num_cards_correct} out of {num_cards_completed} correctly. Your score so far is {score}%.")

# Display feedback message based on score
if score > 90 and score <= 100:
    print("Excellent work!")
elif score > 70 and score <= 90:
    print("Good job!")
elif score > 50 and score <= 70:
    print("Keep practicing!")
elif score > 0 and score <= 50: 
    print("Need more study time!")
else:
    print("Score lies outside range")

Take a break: 🛋️