This small Python script divides a shared household bill among the people living in a flat or hostel. It collects rent food and electricity details from the user calculates the electricity charge and then computes the amount each person should pay. The script is short easy to understand and useful for quick cost sharing.
Read number of persons
- persons = int(input(“Enter number of persons staying in the flat/hostel: “)) prompts for how many people will share the bill and converts the response to an integer.
Read rent amount
- rent = int(input(“Enter your hostel/flat rent: “)) prompts for the total rent and casts it to an integer.
Read food expenses
- food = int(input(“Enter your total food expenses: “)) prompts for the combined food cost and casts it to an integer.
Read electricity usage
- electricity_spend = int(input(“Enter your electricity units spent: “)) asks for the number of electricity units consumed and casts the input to an integer.
Read electricity rate
- charge_per_unit = float(input(“Enter charge per unit: “)) asks for the electricity rate per unit and converts it to a floating point number so decimals are allowed.
Compute electricity bill
- total_bill = electricity_spend * charge_per_unit multiplies units by rate to get the total electricity charge.
Compute per person amount
- total_amount = (rent + food + total_bill) / persons sums rent food and electricity then divides by the number of persons to get the share per person.
Print result
- print(“Total amount per person will be: “, total_amount) displays the per person amount to the user.
How to run this script
Save the code to a file named main.py or any name you prefer.
Open a terminal and run python main.py.
Enter the requested numeric values when prompted. The script will print the amount each person should pay.
Simple improvements you can mention to readers
- Validate inputs and re prompt on invalid entries.
- Prevent zero or negative values for persons rent food or charge per unit.
- Use float for rent and food if fractional amounts are possible.
- Format the printed amount with two decimal places and a currency symbol.
- Optionally split electricity proportionally if some people used more or less power.
Conclusion
This bill splitting script is a concise utility that demonstrates basic user input arithmetic and simple aggregation in Python. It is ideal as a starter project for beginners or as a quick utility to share household costs.