📱 Code Python on your phone with Python Coding - Learn PythonGet the free Android app →
  1. Home
  2. Python exercises
  3. Python basics

Python exercises · 6 tasks

Python basics exercises for beginners

Six warm-up exercises on the very first things every Python programmer learns: printing, variables, reading input, converting numbers and formatting output.

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.

0 / 6 solved

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!

    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.

      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.

        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.

          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.

            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).

              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 →

              Practise on your phone too

              Python Coding - Learn Python for Android: a real Python 3 interpreter, code editor, 26 example programs and 12 marked exercises.

              Get it on Google Play

              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.

              Keep practising

              Updated 2026-10-22 · every solution is tested on Python 3