In: Computer Science
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints a message with information about the total amount owed and how much the tip was.
As a reminder, the tip amounts are 10%, 15% and 20% for stingy, regular, and generous customers. And the tax amount should be 7%.
The total amount is calculated as the sum of two amounts:
To receive full credit, you must use string formatting to print out the result from your function, and your amounts owed should display only 2 decimal places (as in the examples below). To "pretty print" the float to a desired precision, you will need to use this format operator (refer back to class slides for more explanation): %.2f
Print the results to the console like in the example below, including the base cost of the meal, tax, three tip levels, and total for regular customers.
Test cases:
#define function
#code to test / call function here
Thanks for the question, here is the code in python
The 3rd example given in question is incorrect
the customer type in the above passed is generous but why the output is showing for stingy, I think this is incorrect
Here is the function, I have given explanatory names so that you can follow the code precisely and also used pretty formatting.
let me know for any questions or help.
thank you !
===================================================================
def print_tip(base_cost, customer_type):
TAX_PERCENTAGE = 1.07
STINGY_PERCENTAGE = 0.1
REGULAR_PERCENTAGE = 0.15
GENEROUS_PERCENTAGE = 0.20
check_amount = base_cost * TAX_PERCENTAGE
tip_amount = 0.0
if customer_type ==
'regular':
tip_amount =
check_amount * REGULAR_PERCENTAGE
elif customer_type ==
'generous':
tip_amount =
check_amount * GENEROUS_PERCENTAGE
elif customer_type ==
'stingy':
tip_amount = base_cost *
STINGY_PERCENTAGE
total_amount = tip_amount + check_amount
print('Total owed by {} customer = ${}
(with ${} tip)'.format(customer_type,
'%.2f' % total_amount,'%.2f' %
tip_amount))
print_tip(20, 'regular')
print_tip(26.99, 'generous')
print_tip(14.99, 'stingy')