Calculate Change in Harry Potter Currency Using Python

Python Assignment Description

Write a program that calculates the amount of change to be returned from a vending machine using Harry Potter currency. 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. The conversion values for these coins in knuts are as follows:
  • 1 knut = 1 knut
  • 1 sickle = 29 knuts
  • 1 galleon = 493 knuts
The knut is similar to a cent (or penny) in U.S. currency, and the sickle is similar to a U.S. quarter. One dollar equals 4 quarters or 100 cents. In Harry Potter currency, one galleon equals 17 sickles or 493 knuts. The vending machine dispenses 4 options: Assortment of candy for 11 sickles and 7 knuts, Butterbeer for 2 sickles, Daily Prophet for 5 knuts, and Quill for 6 sickles. The vending machine accepts galleons, sickles, and knuts for payment.

Steps to Calculate Change:

Step 1) Display the following to the user: Please select an item from the vending machine:

a) Assortment of Candy for 11 sickles and 7 knuts

b) Butterbeer for 2 sickles

c) Quill for 6 sickles

d) Daily Prophet for 5 knuts

Step 2) Get input form the user using the following prompt: Choice:

Step 3) Have the user enter in the number of galleon, sickles and knuts. When testing, the CTA will only enter in an integer value. Please pay by entering the number of each coin

Number of galleons: 1

Number of sickles: 0

Number of knuts: 0

Step 4) Calculate the cost of the item in knuts and put that into a variable. Calculate the payment in knuts and put that into a variable. Print out the cost and the payment. Here is an example:

Cost in knuts: 326

Payment in knuts: 493

Step 5) If the payment is less than the cost, then print a message to the user saying that the user will not receive their item. Here is an example:

You did not enter enough money and will not receive the Quill

Step 6) If the payment is enough, then calculate the change in knuts. Print the item and the change in knuts. Using the division and modulo operators, calculate the change that will be dispensed in galleons, sickles, and knuts. Print the number of each coin for the change.

Example of output:

You purchased the Assortment of Candy

Your change is 167 knuts

You will be given Galleons: 0 Sickles: 5 Knuts: 22

Step 7) Your code must handle the user entering upper case and lower case letters.

Step 8) Your code must handle the user entering an invalid menu choice.

To complete this program in Python, you will need to use input statements to get the user's choice and payment information. Then, you will need to use mathematical operations to calculate the cost of the item in knuts and the payment in knuts. Next, you will need to use conditional statements to determine if the payment is enough for the selected item. If it is not, you will need to print a message to the user saying they will not receive their item. If the payment is enough, you will need to calculate the change in knuts using division and modulo operators. To dispense the change in the largest possible coins, you will need to use more conditional statements to determine the number of galleons, sickles, and knuts to be returned. Lastly, you will need to handle uppercase and lowercase input from the user, as well as any invalid menu choices. If the user enters an invalid choice, you can just choose an option for them and let them know. Overall, this program will require a lot of mathematical operations and conditional statements in order to correctly calculate the amount of change to be returned in Harry Potter currency.

How can you handle the user entering an invalid menu choice in the Python program for calculating change in Harry Potter currency?

In the Python program, you can handle the user entering an invalid menu choice by implementing a conditional statement to check if the user's choice is within the valid options. If the user enters something other than the choices on the menu, you can inform them that they have entered an invalid option and select a default item for them. This way, you can ensure that the program can handle unexpected inputs and provide a fallback option to proceed with the calculation of change.

← Converting one element arrays in numpy the right way Where are files in usr bin stored →