Question

In: Computer Science

Please use the python and explain. Also please show python. Suppose that a cashier owes a...

Please use the python and explain.

Also please show python.

Suppose that a cashier owes a customer some change and that the cashier only has quarters, dimes, nickels, and pennies. Write a program the computes the minimum number of coins that the cashier can return. To solve this problem use the greedy algorithm explained below. PROBLEM STATEMENT: Your program should first ask the user for the amount of money he/she is owed (in dollars). You may assume that the user will enter a positive number. It should then print the minimum number of coins with which that amount can be made. Assume that the only coins available are quarters (25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent). EXAMPLES: If cashier owes 56 cents (i.e. $0.56) to the customer, the minimum number of coins the cashier can return is 4 (in particular, 2 quarters, 0 dimes, 1 nickel and 1 penny. It is not possible to return 3 or less coins). If cashier owes $1.42 to the customer, the minimum number of coins the customer can return is 9 (in particular 5 quarters, 1 dime, 1 nickel and 2 cents). Thus your program will look like this, for different runs:

Enter the amount you are owed in $: 0.56 The minimum number of coins the cashier can return is: 4

Enter the amount you are owed in $: 1.42 The minimum number of coins the cashier can return is: 9

Enter the amount you are owed in $: 1.00 The minimum number of coins the cashier can return is: 4

Solutions

Expert Solution

I have written the program using PYTHON PROGRAMMING LANGUAGE.

OUTPUT :

CODE :

if(__name__ == "__main__"):

#taking user input

money = float(input("Enter the amount of money he/she is owed (in dollars) : \t"))

print("\nOUTPUT : \n")

#defind the dictionary

dic = {"Quarters":0,"Dimes":0,"Nickels":0,"Pennies":0}

totalcoins = 0

if(money >= 0):

cents = int(money*100)#converting the dollars to cents

while(cents!=0):

if(cents/25 >=1):

cents-=25

dic["Quarters"]+=1

totalcoins+=1

elif(cents/10 >=1):

cents-=10

dic["Dimes"]+=1

totalcoins+=1

elif(cents/5 >=1):

cents-=5

dic["Nickels"]+=1

totalcoins+=1

elif(cents/1 >=1):

cents-=1

dic["Pennies"]+=1

totalcoins+=1

#accessing the item in the dictionary and printing them on the console

for item in dic:

print("{:s} : {:d}".format(item,dic[item]))

#printing the result on the console

print("\nThe minimum number of coins the cashier can return is: {:d}".format(totalcoins))

else:

#in case if the input is invalid

print("INVALID INPUT !!!")

Thanks..


Related Solutions

Do it in python please! also please use this template please I have provided and below...
Do it in python please! also please use this template please I have provided and below is the activity def main(): # import the module random try: # asking the user to enter a number between 1 and 100 #loop time while if elif #for loop # generates that number of random integers and stores them in a list for x in # computations # displays the results on the screen # call try_Again to give the user the opportunity...
Please write the following Python program. Also, show all output work. Computing the Fibonacci and Lucas...
Please write the following Python program. Also, show all output work. Computing the Fibonacci and Lucas Series¶ Goal:¶ The Fibonacci Series is a numeric series starting with the integers 0 and 1. In this series, the next integer is determined by summing the previous two. This gives us: 0, 1, 1, 2, 3, 5, 8, 13, ... We will write a function that computes this series – then generalize it. Step 1¶ Create a new module series.py in the session02...
Please show work and explain. Also, can I use TVM in the TI-83+ to solve? 5-8:...
Please show work and explain. Also, can I use TVM in the TI-83+ to solve? 5-8: Thatcher Corporation’s bonds will mature in 10 years. The bonds have a face value of $1,000 and an 8% coupon rate, paid semiannually. The price of the bonds is $1,100. The bonds are callable in 5 years at a call price of $1,050. What is their yield to maturity? What is their yield to call?
***PYTHON PLEASE*** I'd also like to use decimal to two places when calculating the money $$...
***PYTHON PLEASE*** I'd also like to use decimal to two places when calculating the money $$ values for budget and fee areas. Thank you! -------------------------------------------------------- Create a Park class. Include the following seven data members: Name of Park Location Type of Park (National, State or Local) Fee Number of Employees Number of visitors reported for the past 12 months Annual Budget Write your __init__ class In addition write four separate instance methods that: Return a string containing the name of...
1. Please use Python 3 programing. 2. Please share your code. 3. Please show all outputs....
1. Please use Python 3 programing. 2. Please share your code. 3. Please show all outputs. Create a GUI Calculator with the following: Title : Calculator Label and Entry box for 1st Number Label and Entry box for 2nd Number Buttons for *, /, +, - Label for result and Displaying the result
Can someone please explain how to use superposition. also, to find the current please explain clearly...
Can someone please explain how to use superposition. also, to find the current please explain clearly how to use current dividers. I'll give it a like for the best response
Can you show the formulas for each step also, please? Suppose you have been hired as...
Can you show the formulas for each step also, please? Suppose you have been hired as a financial consultant to Defense Electronics, Inc. (DEI), a large, publicly traded firm that is the market share leader in radar detection systems (RDSs). The company is looking at setting up a manufacturing plant overseas to produce a new line of RDSs. This will be a five-year project. The company bought some land three years ago for $7.1 million in anticipation of using it...
Please explain your answer clearly. Please show all the formulas and calculations (please do not use...
Please explain your answer clearly. Please show all the formulas and calculations (please do not use excel): Anchor Ltd paid $15,000 last quarter for a feasibility study regarding the demand for motorboat replacement parts which would require the purchase of a new metal-shaping machine. Today, they wish to conduct an analysis of the proposed project. The machine costs $250,000 and will operate for five years and tax rules allow the machine to be depreciated to zero over a five-year life....
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
(Please use Python) Suppose that a company sells five products with product codes p101, p107, p122,...
(Please use Python) Suppose that a company sells five products with product codes p101, p107, p122, p125, and p126. The company has three warehouses, which are located in St. Louis, Chicago, and Kansas City. The retail value for each of the five products and the inventory for each of the warehouses are stored in dictionaries, as shown below. Copy the code below into a code cell, and then execute that cell. prices = {'p101':37.52, 'p117':56.98, 'p122':43.72, 'p125':48.33, 'p126':52.45} inventory =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT