1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Delicious77 [7]
3 years ago
15

Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints a message with informati

on about the total amount owed and how much the tip was. You may recognize this program from HW1. We'll write a very similar program, just modifying it and using string formatting. Feel free to copy/paste code from before and modify it. 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: check_amount = base_cost*1.07 tip_amount = tip_percentage*check_amount 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: inputs: check_amount = 20, customer_type = "regular" --> output: Total owed by regular customer = $24.61 (with $3.21 tip) inputs: check_amount = 26.99, customer_type = "generous" --> output: Total owed by generous customer = $34.66 (with $5.78 tip) inputs: check_amount = 26.99, customer_type = "generous" --> output: Total owed by stingy customer = $16.83 (with $1.53 tip)

Computers and Technology
1 answer:
PSYCHO15rus [73]3 years ago
8 0

Answer:

Explanation:

Thanks for the question, here is the code in python

The 3rd example given in question is incorrect

inputs: check_amount = 26.99, customer_type = "generous" --> output: Total owed by stingy customer = $16.83 (with $1.53 tip)

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.

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')

You might be interested in
The temperature in toronto canada was-4°c and tje temperature in brixton,england was 6°c warmer. what was the difference in temp
Oksana_A [137]

Answer:

It is 10°c difference between them

7 0
3 years ago
What is JavaScript? JavaScript is a _____ language.
disa [49]

Answer: dynamic computer language

Explanation:

JavaScript is a dynamic computer language. Hope this helps! (•‿•)

5 0
2 years ago
Read 2 more answers
Which of these is an example of an online workspace?
irakobra [83]
A website that hosts a companies documents
8 0
2 years ago
The country has thousands of privately run social service organizations. Two of the most well-known organizations are
yan [13]

Answer:

Salvation army or Goodwill and YWCA

Explanation:

6 0
3 years ago
Which view of data deals with how the data is actually formatted and located? physical view logical view information view techni
VMariaS [17]
Physical view of data deals with how the data is located and formatted.
7 0
3 years ago
Other questions:
  • Who developed one of the first mathematical models of a multilevel security computer system?
    15·1 answer
  • Keep a log of the different types of communication activities in which you engage during the rest of the day. Categorize each ac
    14·1 answer
  • The most common solution to supply chain uncertainties is to build inventories or __________ as insurance.
    6·1 answer
  • How Oracle 12c advances the security discussion?
    12·1 answer
  • To save a file so that it can be opened on most computers, select the ____ option.
    10·2 answers
  • What principle of interaction is John using?
    9·2 answers
  • Does any of yall play rob lox?
    5·2 answers
  • 1.What is the output of the following program? [10 Marks]namespace ConsoleApp1{class Program{static void Main(string[] args){int
    13·1 answer
  • Which type of address is the ip address 232. 111. 255. 250?.
    15·1 answer
  • What does the ‘SIM’ in the SIM card stand for?
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!