Python fundamentals
Project: study-time calculator
Combine input, variables, arithmetic, and f-strings in a complete beginner program.
Lesson 12 of 63
Reading: about 2 min
Lesson + practice: about 15 min
Difficulty: Beginner
On this page5 sections
Create study_time.py in your python-roadmap folder. The program will ask for a name, a number of sessions, and minutes per session. Enter positive whole numbers for both numeric prompts.
Build the calculator
# Calculate a simple study plan.
name = input("Your name: ")
sessions = int(input("How many study sessions? "))
minutes_per_session = int(input("Minutes per session? "))
total_minutes = sessions * minutes_per_session
hours = total_minutes // 60
remaining_minutes = total_minutes % 60
print(f"{name}, you planned {sessions} sessions.")
print(f"Total study time: {hours} h {remaining_minutes} min.")Your name: Sam How many study sessions? 3 Minutes per session? 25 Sam, you planned 3 sessions. Total study time: 1 h 15 min.
Why this works
Trace the program with one set of inputs: three sessions of 25 minutes gives 75 total minutes. Integer division by 60 gives one complete hour, and the remainder gives 15 minutes. The f-strings then display those calculated values.
Check the result
Run the file with your working Python command, such as python study_time.py. Enter Sam, 3, and 25 at the three prompts. The total should be 1 h 15 min. Run it again with 2 sessions of 30 minutes; the total should be 1 h 0 min.
Completion check
You are ready for Chapter 3 when you can explain each variable and its type, predict the result of the arithmetic, change the output sentence, and explain why int() is needed for the numeric responses.
Why use both // and % in this project?
Reveal answer
// finds whole hours, while % finds the minutes left over.
Try another case
What should the program report for four 20-minute sessions?
Check your answer
Reveal answer
Four sessions total 80 minutes, which is 1 h 20 min.
Your progress
Reveal the check answer or reach the end to complete this lesson.