Practice by topic / Python & code / Python

Python Basics Exercises

Python is the most popular language for automating work: cleaning data, renaming files, crunching numbers. Each exercise runs your real code in the browser and checks it. These 5 exercises build up step by step, starting with print a greeting, store a value, add gst.

3 of 5 free · no sign-up needed · instant feedback

1

Print a Greeting

Free

Print exactly <code>Hello, World!</code>

Show the solution

Text goes in quotes inside print(): print("Hello, World!")

Right — print() sends text to the output. Every Python program you write will use it.

Try it in the live editor →
2

Store a Value

Free

Create a variable called <code>company</code> holding the text <code>Acme Pte Ltd</code>, and a variable called <code>employees</code> holding the number <code>42</code>.

Show the solution

company = "Acme Pte Ltd" on one line, employees = 42 on the next.

Good — text needs quotes, numbers don't. Mixing those up is one of the most common Python bugs.

Try it in the live editor →
3

Add GST

Free

A price before tax is stored in <code>price</code>. Create <code>total</code>: the price plus 9% GST.

Show the solution

Multiply by 1.09: total = price * 1.09

Exactly — price * 1.09 works for any price, which is the whole point of a formula.

Try it in the live editor →
4

Format a Message

Using <code>name</code> and <code>amount</code>, print <code>Invoice for Mei: $120</code> — built from the variables, not typed out.

Solution and instant grading: open it in the practice app (use one of your 20 free picks, or Pro).

Try it in the live editor →
5

Split the Bill

A bill of <code>total</code> is split between <code>people</code>. Create <code>each</code> (the share per person, rounded to 2 decimal places).

Solution and instant grading: open it in the practice app (use one of your 20 free picks, or Pro).

Try it in the live editor →