Hello everyone, In this post, we will learn Python by creating very simple programs.

## 1. Write a Python program that calculates the total bill amount, including tip, and splits it among a specified number of people.

## Can you explain how each part of the program works?”

**Let’s solve this program.**

```
print("Welcome to the tip calculator")
bill = float(input("What was the total bill? Rs: "))
tip = int(input("How much tip would you like to give? 10, 12, or 15?: "))
people = int(input("How many people to split the bill?: "))
tip_as_percent = tip / 100
total_tip_amount = bill * tip_as_percent
total_bill = bill + total_tip_amount
bill_per_person = total_bill / people
final_amount = round(bill_per_person, 2)
final_amount = "{:.2f}".format(bill_per_person)
print(f"Each person should pay: Rs {final_amount} and total bills is Rs: {total_bill}")
```

### Let’s break down the code step by step:

This line prints a welcome message to the user, indicating that they are using a tip calculator.`print("Welcome to the tip calculator")`

:This line prompts the user to input the total bill amount. The`bill = float(input("What was the total bill? Rs: "))`

:`input()`

function takes user input as a string, which is then converted to a floating-point number using`float()`

and assigned to the variable`bill`

.This line prompts the user to input the tip percentage they would like to give. It expects the user to input either 10, 12, or 15. The input is converted to an integer using`tip = int(input("How much tip would you like to give? 10, 12, or 15?: "))`

:`int()`

and assigned to the variable`tip`

.This line prompts the user to input the number of people with whom they want to split the bill. The input is converted to an integer using`people = int(input("How many people to split the bill?: "))`

:`int()`

and assigned to the variable`people`

.This line calculates the tip percentage as a decimal. For example, if the user entered 15,`tip_as_percent = tip / 100`

:`tip_as_percent`

would be 0.15.This line calculates the total tip amount by multiplying the bill amount (`total_tip_amount = bill * tip_as_percent`

:`bill`

) by the tip percentage (`tip_as_percent`

).This line calculates the total bill amount by adding the original bill amount (`total_bill = bill + total_tip_amount`

:`bill`

) to the total tip amount (`total_tip_amount`

).This line calculates the amount each person needs to pay by dividing the total bill (`bill_per_person = total_bill / people`

:`total_bill`

) by the number of people (`people`

).This line rounds the amount each person needs to pay to two decimal places using the`final_amount = round(bill_per_person, 2)`

:`round()`

function.This line formats the rounded amount (`final_amount = "{:.2f}".format(bill_per_person)`

:`bill_per_person`

) as a string with two decimal places using string formatting.This line prints the final amount each person should pay, including the currency symbol “Rs”, the formatted amount (`print(f"Each person should pay: Rs {final_amount} and total bills is Rs: {total_bill}")`

:`final_amount`

), and the total bill amount (`total_bill`

).