# greeter.py, M1 solution: a personalized tip helper. # Every line is explained so you can read it like a sentence. # Run it in Google Colab (paste into a cell) OR on any computer with: python greeter.py # --- 1. Ask the person some questions (input) ------------------------------- # input() prints the question, waits for them to type, and hands back TEXT. name = input("What's your name? ") bill_text = input("How much was the bill? ") tip_text = input("What tip % do you want to leave? ") # --- 2. Turn the text answers into numbers (types) -------------------------- # input() always gives TEXT (a string). To do maths we convert to a number. # float() = a number that can have decimals (like 42.50). bill = float(bill_text) tip_percent = float(tip_text) # --- 3. Do the maths (numbers) ---------------------------------------------- tip = bill * tip_percent / 100 # the tip in dollars total = bill + tip # what they actually pay # --- 4. Say something back, personalized (output + f-string) ---------------- # An f-string lets us drop variables straight into a sentence with { }. # The :.2f rounds a number to 2 decimal places, like money. print(f"\nThanks, {name}! Here's your bill:") print(f" Bill: ${bill:.2f}") print(f" Tip: ${tip:.2f} ({tip_percent:.0f}%)") print(f" Total: ${total:.2f}") print(f"\nYou wrote a real program, {name}. ")