ุงู†ุชู‚ู„ ู„ู„ู…ุญุชูˆู‰
Robo EgyptRobo Egypt
โ˜ฐ Course contents
Robo Python: home
0. Lab tour1
1. The start5
2. Variables and input5
3. Conditions5
4. Loops5
5. Lists4
6. Functions4
7. Drawing with the turtle3
8. The project: the guess-the-number game3
9. Strings in depth1
10. Dictionaries (dict)3
11. Randomness and errors3
12. Classes and objects (class)2
13. Pro drawing and charts3
14. The final project: the quiz game2

๐Ÿ› ๏ธ Section project: the money counter

Section 4: LoopsLesson 4.4 ยท โฑ 10 min
๐ŸŽฏ Project goal
The program asks for the price of 5 things, then prints the total.
total = 0
for i in range(5):
    price = int(input("Price: "))
    total = total + price
print("Total =", total)
๐Ÿ–ฅ๏ธ The output in Robo Python:
Price: 10
Price: 25
Price: 5
Price: 40
Price: 20
Total = 100
๐Ÿ Open the code in Robo Python โ†—

๐Ÿ“Œ Another example: a money box with a goal

We add money until we reach 100.

When the program asks, we type: 40, then 30, then 50.

๐Ÿ A money box with a goal
money = 0
while money < 100:
    add = int(input("Add: "))
    money = money + add
    print("Now:", money)
print("Goal reached!")
๐Ÿ–ฅ๏ธ The output in Robo Python:
Add: 40
Now: 40
Add: 30
Now: 70
Add: 50
Now: 120
Goal reached!
๐Ÿ Open the code in Robo Python โ†—
โœ๏ธ Practise
Challenge: also print the highest price.
โœ๏ธ Practise here in the lessonor open the lab in a new page โ†—

๐ŸŽฏ Challenge yourself

Easy

Save 5 pounds every day: how much after 30 days?

๐Ÿ‘€ Show the solution
๐Ÿ Solution
money = 0
for day in range(30):
    money = money + 5
print(money)
๐Ÿ–ฅ๏ธ The output in Robo Python:
150
๐Ÿ Open the code in Robo Python โ†—

Result: 150

Medium

How many days do you need to collect 200 pounds if you save 15 every day?

๐Ÿ‘€ Show the solution
๐Ÿ Solution
money = 0
days = 0
while money < 200:
    money = money + 15
    days = days + 1
print(days)
๐Ÿ–ฅ๏ธ The output in Robo Python:
14
๐Ÿ Open the code in Robo Python โ†—

Result: 14 days

Hard

A coin counter: the number of 1, 5 and 10 coins, and print the total.

๐Ÿ‘€ Show the solution

When the program asks, we type: 3, then 5, then 4.

๐Ÿ Solution
ones = int(input("1s: "))
fives = int(input("5s: "))
tens = int(input("10s: "))
print("Total:", ones + fives * 5 + tens * 10)
๐Ÿ–ฅ๏ธ The output in Robo Python:
1s: 3
5s: 5
10s: 4
Total: 68
๐Ÿ Open the code in Robo Python โ†—

Result: Total: 68

Finished the lesson? Mark it so your progress counts.