Learn Python basics by building a simple calculator
Six half-hour sessions built on the official Python tutorial. You'll grow one script step by step until it's a calculator that takes user input, handles mistakes, and keeps running until you quit.
Outcome
A working calculator.py that does + - * / and powers from user input, rejects bad input without crashing, blocks division by zero, and repeats until the user quits.
- Every resource is a real public page our team picked. Our server checks the links; if one ever breaks, tell us and we'll replace it.
- Install Python only from python.org or your computer's official app store, never from a random download site.
- Phones and Chromebooks without Linux can't run these scripts directly; a free browser-based Python editor can stand in, but setup steps will differ.
- Decimal results like 0.30000000000000004 are normal computer rounding, not a bug in your code.
- 10,000 seconds is a structured starting point. It builds a real first result, not guaranteed expertise.
Outline
- 127:47
Install Python and run your first script
Python runs on your computer and you can run a .py file from the terminal.
- 227:47
Python as a calculator
Use every arithmetic operator and store results in variables.
- 327:47
Get numbers from the user
Ask the user for two numbers and add them correctly.
- 427:47
Choose the operation with if and elif
Let the user pick + - * or / and get the right answer.
- 527:46
Handle bad input and dividing by zero
Your calculator asks again instead of crashing on bad input or a zero divisor.
- 627:46
Capstone: build the full calculator
A finished calculator that handles five operators, bad input, and repeat calculations until you quit.
Capstone
Your working calculator
A command-line calculator in Python that takes two numbers and an operator, handles bad input and division by zero, and repeats until you quit, plus one feature you added yourself.
Sources
- Built-in Functions
Python Software Foundation (official docs)
Not yet verifiedFree - Download Python
Python Software Foundation
Not yet verifiedFree - More Control Flow Tools
Python Software Foundation (official docs)
Not yet verifiedFree - Errors and Exceptions
Python Software Foundation (official docs)
Not yet verifiedFree - Using the Python Interpreter
Python Software Foundation (official docs)
Not yet verifiedFree - An Informal Introduction to Python
Python Software Foundation (official docs)
Not yet verifiedFree