Skip to content

Commit 36cb30f

Browse files
committed
Added an Expense splitter for group outings
1 parent c1d34bb commit 36cb30f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Expense Splitter/main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
def calculate_split(total_amount: float, number_of_people: int, currency: str) -> None:
2+
if number_of_people < 1:
3+
raise ValueError('Number of people should be at least one.')
4+
5+
# Calculate the share per person
6+
share_per_person: float = total_amount / number_of_people
7+
8+
# Print the results
9+
print(f'Total expenses: {currency}{total_amount:,.2f}')
10+
print(f'Number of people: {number_of_people}')
11+
print(f'Each person should pay: {currency}{share_per_person:,.2f}')
12+
13+
14+
def main() -> None:
15+
try:
16+
# Input for total amount
17+
total_amount: float = float(input('Enter the total amount of the expense: '))
18+
19+
# Input for number of people
20+
number_of_people: int = int(input('Enter the number of people sharing the expense: '))
21+
22+
# Call the function to calculate the split with currency set to rupees
23+
calculate_split(total_amount, number_of_people, currency="₹")
24+
25+
except ValueError as e:
26+
print(f'Error: {e}')
27+
28+
29+
# Run the main function
30+
if __name__ == "__main__":
31+
main()

Expense Splitter/runtme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Python 3.12.3

0 commit comments

Comments
 (0)