A tip calculator
Choose a bill amount and a tip percentage. Print the tip and total. Later, add the number of people splitting the bill.
Learn by doing
Run something small, understand its result and make a change. That is enough to start learning how Python works.
Your first exercise
This script adds three prices and prints the total. Create a Python file, type the example and press Run.
You should see 30. Change one price and predict the new answer before you run it again.
This example uses standard Python and can be tried on Mac, iPhone or iPad.
my_first_script.py
prices = [12, 8, 10]
total = sum(prices)
print("Your total is:")
print(total)Keep experimenting
Replace 10 with 20. Predict the total, then run the script to see whether you were right.
Put a fourth number in the list. You have changed the input without rewriting the calculation.
Try average = total / len(prices), then print the average. You are using the same data to answer a new question.
Examples on Mac
The Mac app includes tutorials for Python basics, arrays, tables and web requests. Open one, run it and use it as a starting point.
Pick the topic closest to what you want to make. It is easier to learn a library when you have a small question for it.
Try a data example next →
Build a learning habit
Choose a bill amount and a tip percentage. Print the tip and total. Later, add the number of people splitting the bill.
Store a question and answer. Ask for input, compare the response and print feedback. Then add another question.
Store pages read each day in a list. Add them up and calculate an average. On Mac, try turning the numbers into a chart.
When you get stuck
Read the message and the line it points to. Check spelling, brackets and indentation. Try simplifying the script until you can see the cause.
Yes. Write and run small scripts in the mobile app. Its guidebook and learning resources can help you explore the language; some features require a subscription.
It can help explain a line or suggest where to look. Ask for an explanation, then run and check the code yourself so you understand the result.
Choose your device and try the four-line exercise above.