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 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?
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...
***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...
Python Programming, Could you also show the right indents in Python Shell. Below are the skeleton...
Python Programming, Could you also show the right indents in Python Shell. Below are the skeleton of the program, and the input and output. # Initialize list mylist = [ ] # Set up loop to put menu on screen num = 1 while num != 0:      print(" ")     print(" ")     print("            Menu ")      print ("0 - Quit")     print ("1 - Add item to list")     print ("2 - Pop item off list and print...
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
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 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 step by step what is going on each step Also show how the output...
Please explain step by step what is going on each step Also show how the output is coming. I would rate positively. Thank you so much . #include     <stdio.h>   #include   <string.h>    int   main()   {          char   buffer[16],   *pos;          printf("Enter   string:   ");          if   (!(fgets(buffer,sizeof(buffer),stdin)))   {                      printf("End   of   file\n");                      return   0;          }          printf("Length   of   %s   is   %lu   \n",buffer,strlen(buffer));          if   ((pos=strchr(buffer,  ...
HOW WOULD YOU WRITE THIS IN PYTHON? SHOW THIS IN PYTHON CODE PLEASE # DEFINE 'all_keywords',...
HOW WOULD YOU WRITE THIS IN PYTHON? SHOW THIS IN PYTHON CODE PLEASE # DEFINE 'all_keywords', A LIST COMPRISED OF ALL OUR NEGATIVE SEARCH KEYWORDS AS REQUIRED BY THE PROJECT # FOR EACH ELEMENT IN 'full_list' (THE LIST OF LISTS YOU WOULD HAVE CREATD ABOVE THE PREVIOUS LINE) # INITIALIZE THE SET 'detected_keywords' TO EMPTY # DEFINE VARIABLE 'current_reviewer' FROM CURRENT ELEMENT OF 'full_list' BY EXTRACTING ITS FIRST SUB-ELEMENT,... # ...CONVERTING IT TO A STRING, AND THEN STRIPPING THE SUBSTRING...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT