EXERCISE 4: Calculate scores and statistics with basic arithmetic operations
- What are operations?
- Operators
- Arithmetic operations
- Variables (revisited)
- String formatting (revisited)
Task 1: Create a simple score calculator using arithmetic operations. Start by specifying some score and progress information that you would like to display to the user. You should decide on some variable names corresponding to these pieces of information. E.g.
- Number of cards completed -
num_cards_completed - Number of cards correct -
num_cards_correct - Current score -
score = (num_cards_correct/num_cards_completed) * 100Use arithmetic operations to implement the calculation of the score (and any other statistics or performance metrics you want to include).
Task 2: Craft a user-friendly message to display the score along with some progress metrics.
Use string formatting to write a message with the numerical values.
E.g.
Message: f"You have answered {num_cards_correct} out of {num_cards_completed} correctly. Your score so far is {score}%."
Run and check: Run your code in the terminal to make sure it works with the command
python flashcards_app.py
Experiment by setting the variables to different values and checking the outputs are in line with what you expect (calculate them independently first).
E.g. for the variables and calculation defined above, what do you expect the output to be when:
num_cards_completed = 3andnum_cards_correct = 2?num_cards_completed = 5andnum_cards_correct = 0?num_cards_completed = 10andnum_cards_correct = 5?num_cards_completed = 0andnum_cards_correct = 0? This should throw a division by zero error
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 4: Calculate scores and statistics with basic arithmetic operations” and save your work to Github with the standard Git workflow.
(Re)read the guides:
- What are operations?
- Operators
- Arithmetic operations
- Variables (revisited)
- String formatting (revisited)
Example solution
flashcards_app.py
# 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 (Task 1)
num_cards_completed = 10
num_cards_correct = 5
score = (num_cards_correct/num_cards_completed) * 100
# Display score information (Task 2)
print(f"You have answered {num_cards_correct} out of {num_cards_completed} correctly. Your score so far is {score}%.")
Take a break: 🍰
