Skip to content

Commit 30a5de7

Browse files
authored
Merge pull request #19 from kajal-jotwani/Expense-splitter
Added an Expense splitter for group outings (#14)
2 parents c1d34bb + 5dba37c commit 30a5de7

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

Expense Splitter/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Expense Splitter
2+
3+
A simple Python script to split expenses among a group of people.
4+
5+
## Features
6+
7+
- Calculates the share per person based on the total amount and number of people.
8+
- User-friendly prompts and case-insensitive confirmation.
9+
10+
## Usage
11+
12+
1. Clone the repository.
13+
2. Navigate to the project directory.
14+
3. Run the script:
15+
```bash
16+
python main.py

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)