EXERCISE 3: Convert user inputs to appropriate data types
Task: Write code to ask the user how many cards they would like to practice in a session and save it as a numerical variable so it can be used in calculations later.
You will need to fetch the input from the user and then convert it into an integer before saving it to a variable. Choose a sensible name for the variable, e.g. max_cards_per_session. To confirm the conversion has worked correctly, print out a message confirming the number entered to the user and the type of the variable. The type should be <class 'int'>.
Run and check: Run your code in the terminal to make sure it works with the command
python flashcards_app.py
You should see your welcome message along with your preciously implemented request for their name, e.g.
Welcome to my learning app!
What is your name?
Then when you enter your name, e.g. Alex, and press enter, you should see a welcome message with this name, e.g.:
Hello Alex!
Then you should see your request for the number of cards per session to practice, e.g.:
How many cards would you like to practice?
Then when you enter the number of cards, you should see your message with both the number you entered, e.g. 5, and the type, which should be <class 'int'>, e.g.:
I would like to practice 5 cards per session (<class 'int'>)
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 3: Convert user inputs to appropriate data types” 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
# 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 ({type(max_cards)})")
# For the real app, remove (type(max_cards)) since there's no need for this to be displayed
Take a break: 🌳
