In this Python code snippet, we create a simple tip calculator to make splitting bills a breeze. The program prompts the user for the total bill amount, desired tip percentage, and the number of people sharing the bill. It then calculates the individual share after applying the tip and displays the result. With clear prompts and straightforward calculations, this script is a handy tool for quick calculations when dining out with friends.
print("This is a Tip Calculator\n")
# Get the total bill amount from the user
bill = float(input("What was the total bill? \nSEK"))
# Get the tip percentage from the user
tip = float(input("How much % would you like to tip? 10, 12, 15? \n"))
# Get the number of people to split the bill with
people = int(input("How many people to split the bill with? \n"))
# # Calculate the tip amount as a percentage of the total bill
tip_as_percent = tip / 100
total_tip_amount = bill * tip_as_percent
# # Calculate the total bill including the tip
total_bill = bill + total_tip_amount
# Calculate the bill amount per person
bill_per_person = total_bill / people
# Round the final amount per person to two decimal places
final_amount_per_person = round(bill_per_person, 2)
#
/Display the amount each person needs to pay
print(f'Each person pays {final_amount_per_person} SEK.')
There is another code to make it shorter and simpler.
print("This is a Tip Calculator\n")
# Get the total bill amount from the user
bill = float(input("What was the total bill? \nSEK"))
# Get the tip percentage from the user
tip = float(input("How much % would you like to tip? 10, 12, 15? \n"))
# Get the number of people to split the bill with
people = int(input("How many people to split the bill with? \n"))
# Calculate individual share after applying the tip
tip_as_percent = tip / 100
total_tip_amount = bill * tip_as_percent
final_amount_per_person = round((bill + total_tip_amount) / people, 2)
# Display the result
print(f'Each person pays {final_amount_per_person} SEK.')
*This project is part of the 100 Days of Code: The Complete Python Pro Bootcamp