In the wizarding world of Harry Potter, the currency system is not based off dollars and cents, but instead 3 different coins: knuts, sickles, and galleons. You will be writing a program that simulates the amount of change that is dispensed from a vending machine using this currency system based on the following requirements:

The conversion values for these coins in knuts are as follows:

1 knut = 1 knut
1 sickle = 29 knuts
1 galleon = 493 knuts

This vending machine dispenses 4 different items: Butterbeer for 58 knuts, Quill for 10 Knuts, The Daily Prophet for 7 knuts, and Book of Spells for 400 knuts.

Display the following to the user:

Please select an item from the vending machine:
a) Butterbeer: 58 knuts
b) Quill: 10 knuts
c) The Daily Prophet: 7 knuts
d) Book of Spells: 400 knuts

Get input from the user with the following prompt: >

After selecting an item, ask the user if they are willing to share their purchase on Instagram. If so, they will receive a 5 knut discount, and then use that number to determine the discounted price of the selected item.

Since items in the vending machine cost less than 493 knuts, only 1 galleon (worth 493 knuts) will be accepted to pay for the item. You must determine the change that will be dispensed in sickles and knuts.

Use division and modulus operators to figure out the change.

Create variables to hold information.

You must dispense change in the largest possible units. Include the amount of change being calculated in your output. For example, if an item costs 423 knuts, you have to find change for 70 knuts. You may not simply return 70 knuts; it should be 2 sickles, and 12 knuts.

Do not hard code in the values for the change for each item. You must use arithmetic operations to determine the correct change.

Important: You code must handle the follow user input errors:

  • CapitALizaTioN: The program must allow the user to enter either upper or lower case strings (e.g. either Y or y )
  • Invalid menu choice: If the user enters a choice other the options provided (e.g. a, b, c, or d), your program should tell them they have entered incorrectly. Since we have not covered how to repeat code yet, it is acceptable to tell the user they have been assigned a default choice (i.e. just pick an option for them)

Be sure to comment your code. This means that there should be comments throughout your code. Generally, a comment for every section of code explaining what it does. Points will be deducted for not having comments.

Follow coding conventions.

Sample Output 1

Please select an item from the vending machine:
a) Butterbeer: 58 knuts
b) Quill: 10 knuts
c) The Daily Prophet: 7 knuts
d) Book of Spells: 400 knuts
>b
Will you share this on Instagram (y/n)? y
Thanks! You get 5 knuts off your purchase.
You bought a Quill for 10 knuts (with coupon of 5 knuts) and paid with one galleon.
Here is your change (488 knuts):
Sickles: 16
Knuts: 24

Sample Output 2

Please select an item from the vending machine:
a) Butterbeer: 58 knuts
b) Quill: 10 knuts
c) The Daily Prophet: 7 knuts
d) Book of Spells: 400 knuts
>d
Will you share this on Instagram (y/n)? N
You bought a Book of Spells for 400 knuts (with coupon of 0 knuts) and paid with one galleon.
Here is your change (93 knuts):
Sickles: 3
Knuts: 6

Sample Output 3

Please select an item from the vending machine:
a) Butterbeer: 58 knuts
b) Quill: 10 knuts
c) The Daily Prophet: 7 knuts
d) Book of Spells: 400 knuts
>x
You have entered an invalid option. You will be given a Butterbeer for 58 knuts.
Will you share this on Instagram (y/n)? Maybe
You have entered an invalid option. No coupon will be used.
You bought a Butterbeer for 58 knuts (with coupon of 0 knuts) and paid with one galleon.
Here is your change (435 knuts):
Sickles: 15
Knuts: 0

Optional

Revise the vending machine so that it can accept more than one galleon.

The user would be able to enter any amount of each of the coins, and the proper change should still be returned.

You may adjust the prices of the items in the vending machine, or add more. items.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.