-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added python program for tip calculator - Tipcalculator.py
- Loading branch information
1 parent
045ec95
commit fa90a8f
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
Program's_Contributed_By_Contributors/Python_Programs/Tipcalculator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Function to calculate the tip | ||
def tip_calc(tip_perc, bill): | ||
return tip_perc * bill / 100 | ||
|
||
# Function to execute the tip calculation logic | ||
def calculate_tip(): | ||
try: | ||
tip_percentage = float(input("Enter the tip percentage: ")) | ||
bill_amount = float(input("Enter the amount of the bill: ")) | ||
|
||
if tip_percentage < 0 or bill_amount < 0: | ||
raise ValueError("Please enter positive values.") | ||
|
||
tip_amount = tip_calc(tip_percentage, bill_amount) | ||
total_amount = bill_amount + tip_amount | ||
|
||
# Display the results using descriptive sentences without formatting | ||
print("The calculated tip is: " + str(tip_amount) + " rupees.") | ||
print("The total amount to be paid, including the tip, is: " + str(total_amount) + " rupees.") | ||
except ValueError as e: | ||
print("Input Error: " + str(e)) | ||
|
||
# Start the tip calculation process | ||
calculate_tip() | ||
|
||
|
||
|