Question

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. Sample Output Enter the item price in cents 32 Change due is 68 cents. Quarters: 2 Dimes: 1 Nickels: 1 Pennies: 3

Python, Use formatting

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Explanation:

Code in PYTHON is given below
Output is given at the end
Note : Suppose due is 68 and we need to see how many Quarters coins
we can cover then we need to divide due/25 which gives us 2

And then we take modulo i.e remainder of division of due by 25
which gives us 18.
Similary we calculate for Dimes, Nickels and Pennies

CODE IN PYTHON:

cents = int(input('Enter the item price in cents:'))
due = 100-cents
print('Change due is',due,'cents.')
quarters = due//25
print('Quarters:',quarters)
due = due%25
dimes = due//10
print('Dimes:',dimes)
due = due%10
nickels = due//5
print('Nickels:',nickels)
due = due%5
pennies = due
print('Pennies:',pennies)


OUTPUT:

TEST CASE 1:

Enter the item price in cents:32
Change due is 68 cents.
Quarters: 2
Dimes: 1
Nickels: 1
Pennies: 3

TEST CASE 2:

Enter the item price in cents:50
Change due is 50 cents.
Quarters: 2
Dimes: 0
Nickels: 0
Pennies: 0

Please provide the feedback!!
Thank You!!

Add a comment
Know the answer?
Add Answer to:
All items at a "Penny Fair" are priced less than $1.00. Write a program that makes...
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
  • Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10...

    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)...

  • (In Python 3) Write a program with total change amount as an integer input, and output...

    (In Python 3) Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes So...

  • C++ Write a program that helps a young student learn to make change. Use the random...

    C++ Write a program that helps a young student learn to make change. Use the random number generator to generate change amounts between1¢ and 99¢. Ask the user how many quarters, dimes, nickels and pennies they need to make that amount. Determine whether the coins specified by the user total the specified amount and give them feedback on their answer including whether they used the minimum or optimum number of coins to produce the amount. Sample output of a program...

  • write a PHP program makes change for a given number of cents. The program should ask...

    write a PHP program makes change for a given number of cents. The program should ask the user for the amount of cents and then output the change for specific denominations of ten dollar bills, five dollar bills, one dollar bills, quarters, dimes, nickels, and pennies. Here is a sample program output for an input of 265 cents: Change for 2 dollars and 65 cents : 0 ten dollar bills 0 five dollar bills 2 one dollar bills 2 quarters...

  • 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...

  • Write a program with total change amount as an integer input, and output the change using...

    Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes

  • 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...

  • Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to...

    Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to enter a bill value (1 = $1 bill, 5 = $5 bill, etc.) and the price of an item they want to buy in pennies and calculate their change amount in dollars, quarters, dimes, nickels, and pennies. Your code should start like this: ## # This program simulates a vending machine that gives change # Define constants PENNIES PER DOLLAR = 100 PENNIES PER...

  • 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...

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