Quick answerStart with these six beginner Python exercises: print a message, swap two variables, convert input() to numbers, calculate an average, convert temperatures and format a receipt with f-strings. Each one is checked automatically in your browser and has a hint and a full solution.
Before you start
You need three ideas: print() shows text, = stores a value in a variable, and input() reads a line the user types — always as a string, so use int() or float() to turn it into a number. Write your answer in the editor under each task and press Check; the tests feed your program the inputs shown and compare its output.
Exercises
1. Hello, nameeasy
Read a name with input() and print Hello, NAME!. For the input Ada the output is Hello, Ada!
💡 Use an f-string: f"Hello, {name}!"
Show solution
name = input()
print(f"Hello, {name}!")
An f-string replaces {name} with the variable's value. print("Hello, " + name + "!") works too.
2. Add two numberseasy
Read two whole numbers (one per line) and print their sum.
💡 input() returns text, so "3" + "4" is "34". Convert with int() first.
Show solution
a = int(input())
b = int(input())
print(a + b)
The starter prints 34 because adding strings joins them. int() turns each string into a number before adding.
3. Swap two variableseasy
The program reads a and b. Swap their values so that the final print shows them the other way round. Don't change the last line.
💡 Python can swap in one line: a, b = b, a
Show solution
a = input()
b = input()
a, b = b, a
print(a, b)
a, b = b, a builds the tuple (b, a) first and then unpacks it, so no temporary variable is needed.
4. Average of threeeasy
Read three numbers (they may have decimals) and print their average rounded to 2 decimal places.
💡 Convert with float(), add, divide by 3, then round(value, 2).
Show solution
x = float(input())
y = float(input())
z = float(input())
print(round((x + y + z) / 3, 2))
round(7/3, 2) gives 2.33. Note that round(20.0, 2) prints 20.0 — round keeps it a float.
5. Celsius to Fahrenheitmedium
Read a temperature in Celsius and print it in Fahrenheit with one decimal place, followed by °F. Formula: F = C × 9/5 + 32. Input 100 prints 212.0°F.
💡 Format with f"{f:.1f}°F" — :.1f means one digit after the decimal point.
Show solution
c = float(input())
f = c * 9 / 5 + 32
print(f"{f:.1f}°F")
:.1f inside an f-string formats a float with exactly one decimal, so 97.88 becomes 97.9.
6. Format a receiptmedium
Read an item name, a price and a quantity. Print the total like 3 x Coffee = $7.50 (price × quantity, always two decimals).
💡 f"{qty} x {item} = ${price * qty:.2f}"
Show solution
item = input()
price = float(input())
qty = int(input())
print(f"{qty} x {item} = ${price * qty:.2f}")
The $ is just a character; {price * qty:.2f} does the maths and pads to two decimals.
Next topic: String exercises →
Python Coding - Learn Python for Android: a real Python 3 interpreter, code editor, 26 example programs and 12 marked exercises.
Frequently asked questions
What are good Python exercises for absolute beginners?
Start with input and output: greeting a user, adding two numbers, swapping variables and formatting a result. They teach print(), input(), type conversion and f-strings — the base of everything else.
Why does my program print 34 instead of 7?
input() returns a string, and + joins strings. Convert with int() or float() before doing maths.
Do I need to install Python for these exercises?
No — the editor on each exercise runs real Python in your browser.