Question: main This function is already complete. It calls the other 2 functions to accomplish its work: The main function calls get_item_cost 3 times to get

main

This function is already complete. It calls the other 2 functions to accomplish its work:

  • The main function callsget_item_cost3 times to get the item costs for paperbacks, hardbacks, and magazines.
  • Then the main function callscalc_and_display_receiptto print the receipt.

get_item_cost

This function will need to be implemented.

  • This function takes two parameters:
    • max_allowed maximum number of items the user can enter
    • unit_price the cost of each item
  • The function will ask the user to enter the number of items. If the user enters less than 0 or more than the max allowed, an error message will be printed and they will be asked to enter a different value. See the sample output for an example.
  • After getting a valid number of items, the function will calculate the total cost of the item using the unit_price that was passed in as a parameter.
  • The function will then return the total cost of the item.

calc_and_display_receipt

This function will need to be implemented.

  • This function takes three parameters:
    • pb_total total cost of paperbacks
    • hb_total total cost of hardbacks
    • m_total total cost of magazines
  • The function will calculate the total before tax.
  • The function will calculate the sales tax using the function you created. Use the provided global constant for the sales tax.
  • The function will calculate the total after tax.
  • Then the function will print a receipt that contains the following information:
    • Total cost of paperbacks (if zero, skip this step)
    • Total cost of hardbacks (if zero, skip this step)
    • Total cost of magazines (if zero, skip this step)
    • A divider line
    • Subtotal before tax
    • Amount of tax to be charged
    • Total including tax

You should fill in the parameters needed 35 36 37 38 39 40 = TAX_RATE = 0.07 # 7% sales tax PB_MAX = 50 PB_COST = 2.50 HB_MAX = 20 HB_COST = 7.00 MAG_MAX = 35 MAG_COST = 3.95 = idef get_item_cost(max_allowed, unit_price): while True: # Ask the user how many Paperback books they want pb_num int(input("Paperbacks - Enter the number of items: ")) # Add error message and loop back to while until input is correct while PB_MAX 50: print("Enter a number between 1 and 50.") hb_num = int(input("Hardbacks - Enter the number of items: ")) # Add error message and loop back to while until input is correct while HB_MAX 20: print("Enter a number between 0 and 20.") mag_num = int(input("Magazines - Enter the number of items: ")) # Add error message and loop back to while until input is correct while MAG_MAX 35: print("Enter a number between 0 and 35.") # Return after input error return calc_and_display_receipt() def calc_and_display_receipt(): def main(); print('Paperbacks end='') ON

To show I've attempted this and I'm not just looking for a free handout -

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!