Home › AI + Python: Build a Chai Chatbot › Lesson 8

Bill jodo: int + maths

AI + Python: Build a Chai Chatbot, lesson 8 of 8. simple English notes and code you can run, free.

Open the interactive lesson with Run button

The idea

3 chai and 2 samosa: how much is the bill? Today the bot adds it up for you.

First write the prices in variables: chai_price = 10 and samosa_price = 15.

There is one catch. input() always gives you text, even if you type 3. You cannot multiply the text "3".

Wrap it in int(): int(input("Kitni chai? ")). Now it is a real number, and Python can do the maths.

The code

chai_price = 10
samosa_price = 15
naam = input("Aapka naam? ").strip().title()
chai = int(input("Kitni chai? "))
samosa = int(input("Kitne samosa? "))
bill = chai * chai_price + samosa * samosa_price
print(f"{naam} bhai, aapka bill {bill} rupaye!")

Output:

Aapka naam? Raj
Kitni chai? 3
Kitne samosa? 2
Raj bhai, aapka bill 60 rupaye!

Try it yourself

Remember

input() gives text, int() turns it into a number. Next: Part 9, what if someone types abc?

← Remember the name: input + variable

All lessons: AI + Python: Build a Chai Chatbot