Skip to content

Commit 6cbc78d

Browse files
Add files via upload
1 parent 7d80bda commit 6cbc78d

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎shoppingdiscountcalc.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
valid = False
2+
while not valid:
3+
try:
4+
bill = float(input("Enter the bill amount: "))
5+
discount_percent = float(input("Enter the discount percentage: "))
6+
num_people = int(input("Enter the number of people: "))
7+
discount_amount = bill * (discount_percent / 100)
8+
final_bill = bill - discount_amount
9+
per_person = final_bill / num_people
10+
except ValueError:
11+
print("Please type numbers only.")
12+
except ZeroDivisionError:
13+
print("Number of people cannot be 0.")
14+
else:
15+
print(f"Final bill: ${final_bill:.2f}")
16+
print(f"Each person pays: ${per_person:.2f}")
17+
valid = True
18+
finally:
19+
print("Attempt finished.")

0 commit comments

Comments
 (0)