Question

Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters

Notes and Hints: 1. To clarify the project specifications, sample output is appended to the end of this document. 2. Items 1-

# purchase price and payment will be kept in cents quarters10 dimes 10 nickels10 pennies 10 print WnWe Icome to change-mak i

Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters, and 10 pennies. 2. Repeatedly prompt the user for a price in the form xX.xx, where X denotes a digit, or to enter q' to quit 3. When a price is entered a. If the price entered is negative, print an error message and start over requesting either a new price or to quit (indicated by entering a 'q) b. Prompt for the number of dollars in payment. If the payment is insufficient, print an error message and reprompt for payment. c. Next determine the coins to be dispensed as change. This calculation will depend on the amount to be dispensed and also on the number of coins left in the stock. For example, the least number of coins needed to make change of $1.30 is 6: 5 quarters and 1 nickel. But if there are only 3 quarters, 3 dimes, and 10 nickels left in the stock, then the least number is 11: 3 quarters, 3 dimes, and 5 nickels. d. Print the numbers of the coins to be dispensed as change and their denominations. (Omit a denomination if no coins of that denomination will be dispensed.) e. In case exact payment is made, print a message such as "No change. f. If the change cannot be made up with the coins remaining, print an error message and halt the progranm Just before quitting, print the total amount (the number of dollars and number of cents) left in the stock. 4.
Notes and Hints: 1. To clarify the project specifications, sample output is appended to the end of this document. 2. Items 1-6 of the Coding Standard will be enforced for this project. We provide a proj02.py program for you to start with. It has a simple while loop (notice how input is prompted before the loop and at the bottom of the loop 4. 3. Floating point numbers can be difficult to work with due to the imprecision of representing real numbers in a finite number of computer-memory bits. To avoid imprecision do your calculations in cents, i.e. as type int. For example, $1.15 is the same as 115 cents. To see the problem, try evaluating 1.15*100 in the Python shell and compare that to evaluating round (1.15*100) 5. There are many ways to calculate the maximum number of quarters to make change using the greedy algorithm a. One is with a while loop where you keep subtracting 25 from the amount of change due and increment the number of quarters. End the loop when there are less than 25 cents due or you are out of quarters. After determining quarters you can determine dimes in the same way, e.g. using 10 instead of 25. Work your way down through the other coins b. Alternatively, use the quotient (I) operation for integers for finding the numbers of each coin. For example, 195//25 is 7, the most number of quarters in 195 cents. However, be careful: if the stock has fewer than 7 quarters left, you will only be able to dispense the number left in the stock. For example, if there are only 6 quarters left, then you can dispense only 6 quarters and must use dimes and nickels to make up any remaining change. When we learn about formatting strings, we can more easily and elegantly print monetary amounts. For now, just use the Python print(...) command with appropriate string and/or integer arguments to print the number of dollars and the number of cents 7. 6. One tricky control issue is how to end the program if you run out of coins in the stock. The sample proj02.py program provides a clue with the empty_stock Boolean. The problem is that break only breaks out of the current, innermost loop whereas you may be within multiple loops so when you break you can set the empty_stock Boolean to True and use that to break out of the enclosing loops 8. You do not need to check for any input errors other than those mentioned in this description 9. You may not use advanced data structures such as lists, dictionaries, sets or classes in solving this problem
# purchase price and payment will be kept in cents quarters10 dimes 10 nickels10 pennies 10 print "WnWe Icome to change-mak ing program.") print "WnStock: quarters, dimes, nickels, and pennies" .format quarters, dimes, nickels, pennies)) in_strinput("Enter the purchase price (xx.xx) or 'q' to quit:" while in_str- 'q' # Fill in the good stuff here instead of the following print pr int("Testing: ", in_str) pr int("WhStock: quarters, 0 dimes, quarters, dimes, nickels, pennies)) nickels, and pennies" .format( in strinput( "Enter the purchase price (xx.xx) or 'q' to quit: ")
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

quarters=10
dimes=10
nickels=10
pennies=10

print('Welcome to the chenage-making program')
print('Stock : {} quarters, {} dimes, {} nickels, and {} pennies'.format(quarters,dimes,nickels,pennies))

while True:
int_str=input("\nPlease enter the price in form of XX.XX or q to stop: ")
if(int_str=='q'):
break
price=float(int_str)
if(price>0):
break
else:
print('Please enter the positve value.')

while(int_str!='q'):
while True:
dollar=float(input('\nEnter the number of dollar for payment: '))
if(dollar>price):
price=price*100
dollar*=100
break
else:
print('Insufficient amount!!')

noOfQuarters=0
noOfDimes=0
noOfNickels=0
noOfPennies=0
change=dollar-price
print('Your change is $',(change/100))
noOfQuarters=int(change/25)
if(noOfQuarters<=quarters):
quarters-=noOfQuarters
change-=noOfQuarters*25
else:
noOfQuarters=quarters
quarters=0
change-=noOfQuarters*25

noOfDimes=int(change/10)
if(noOfDimes!=0):
if(noOfDimes<=dimes):
dimes-=noOfDimes
change-=noOfDimes*10
else:
noOfDimes=dimes
dimes=0
change-=noOfDimes*10

noOfNickels=int(change/5)
if(noOfNickels!=0):
if(noOfNickels<=nickels):
nickels-=noOfNickels
change-=noOfNickels*5
else:
noOfNickels=nickels
nickels=0
change-=noOfNickels*5

noOfPennies=change
if(noOfPennies!=0):
if(noOfPennies<nickels):
pennies-=noOfPennies
else:
noOfPennies=nickels
pennies=0

totalCoin=noOfDimes+noOfNickels+noOfPennies+noOfQuarters
print('\nLeast number of coin needed to change is {}'.format(int(totalCoin)))
if(noOfQuarters!=0):
print('{} quarters'.format(noOfQuarters))
if(noOfDimes!=0):
print('{} dimes'.format(noOfDimes))
if(noOfNickels!=0):
print('{} nikckles'.format(noOfNickels))
if(noOfPennies!=0):
print('{} pennies'.format(noOfPennies))

print('\nStock : {} quarters, {} dimes, {} nickels, and {} pennies'.format(quarters,dimes,nickels,pennies))

while True:
int_str=input("\n\n\nPlease enter the price in form of XX.XX or q to stop: ")
if(int_str=='q'):
break
price=float(int_str)
if(price>0):
break
else:
print('Please enter the positve value.')

outputs

code snaps

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ HW Question Your program will simulate a simple change maker for a vending machine. It...

    C++ HW Question Your program will simulate a simple change maker for a vending machine. It will start with a stock of coins and dollars. It will then repeatedly request the price for an item to be purchased or to quit. If given a price, it will accept nickels, dimes, quarters, one-dollar and five-dollar bills—deposited one at a time—in payment. When the user has deposited enough to cover the cost of the item, the program will calculate the coins to...

  • All items at a "Penny Fair" are priced less than $1.00. Write a program that makes...

    All items at a "Penny Fair" are priced less than $1.00. Write a program that makes change with a minimum number of coins when a customer pays for an item with a one dollar bill. Prompt for the item price in cents, report the change due, and the number of coins of each denomination required. Use only quarters, dimes, nickels, and pennies for change (no 50 cent pieces). See sample output but your program should work for any item price....

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • PLease help!!! how to type them in Python !!!! Python help!! THank you so much Problem...

    PLease help!!! how to type them in Python !!!! Python help!! THank you so much Problem 1: (20 points) Optimal change You will write a program that uses the // and % operators to figure out how to give change for a specified amount using the minimum number of coins (quarters, dimes, nickels, cents). The good news is that our currency is specifically designed to make this problem easy. For a given number of cents, first use as many quarters...

  • Write a program that tells what coins to give out for as change from 1 cent...

    Write a program that tells what coins to give out for as change from 1 cent to 99 cents. Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies) only. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Solution Demo Hello I am the coin machine! I will give you the least number of coins for your change....

  • Write a C program that calculates exact change. In order to receive full credit, please remember...

    Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...

  • Write a program called CountCoins.java that prompts the user for the input file name (you can...

    Write a program called CountCoins.java that prompts the user for the input file name (you can copy the getInputScanner() method given in the ProcessFile assignment) then reads the file. The file contains a series of pairs of tokens, where each pair begins with an integer and is followed by the type of coin, which will be “pennies” (1 cent each), “nickels” (5 cents each), “dimes” (10 cents each), or “quarters” (25 cents each), case-insensitively. Add up the cash values of...

  • I need this answer as soon as possible if anyone can help! Thank you! Place the...

    I need this answer as soon as possible if anyone can help! Thank you! Place the lines of code in the correct order so that the program requests an input amount less than one dollar, and then makes change for the given amount using the least number of coins print("tCents:", cents) remainder amount print("Nickels:", nickels, end"") remainder 96-10 remainder 25 nickels-remainder 5 amount int(input(Enter amount of change:") dimes remainder// 10 cents- remainder print( Quarters", quarters, end"") quarters remainder I/ 25...

  • Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume...

    Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume that the coins with which you make change are quarters, dimes, nickels and pennies. Thus you are going to set n = 4 in your program. The amount k for which you have to make change will be provided by the user and your program will return the minimum number of coins needed and also the break-up of the change in terms of the...

  • Objectives: Use the while loop in a program Use the do-while loop in a second program...

    Objectives: Use the while loop in a program Use the do-while loop in a second program Use the for loop in a third program Instructions: Part A. Code a for loop to print the Celsius temperatures for Fahrenheit temperatures 25 to 125. C = 5/9(F – 32).Output should be in a table format: Fahrenheit Celsius 25 ? . . . . . . . . Turn in the source and the output from Part A. Part B. Code a while...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT