Home › Python with Chai › Lesson 7
Mini project: the chai bill
Python with Chai, lesson 7 of 20. A short Hinglish video, simple English notes and code you can run, free.
Open the interactive lesson with Run button
The idea
Everything so far, together: the menu is a dictionary and the order is a list.
The bill() function uses a for loop to add up the price of each item.
An if gives a 5 rupee discount on bills over 50.
The code
menu = {"Masala": 20, "Adrak": 15}
order = ["Masala", "Adrak", "Masala"]
def bill(order):
total = 0
for item in order:
total += menu[item]
if total > 50:
total -= 5
return total
print("Total:", bill(order))
Output:
Total: 50
Try it yourself
- Add one more "Adrak" to the order. What is the new total?
- Change the discount to 10%.
Remember
You're a Python coder now!
← Dictionaries: the chai menu card · input: ask the customer →
All lessons: Python with Chai