Python Forum
Need help with coin change program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with coin change program
#1
Write a program that reads an input representing a change which is an amount less than 1 dollar. The program calculates the change into 50, 10, 5 and 1 cent coins. The program then displays the number of each coin required for that change. E.g.
Enter change: 47
50 cent: 0
10 cent: 4
5 cent: 1
1 cent: 2

def main():
           print("This program calculates the change")
           amount = int(input("Enter the amount: "))
           half = amount // 50
           print("50 cent: ", half)
           dimes = amount // 10
           print("10 cent: ", dimes)
           nickels = amount // 5
           print("5 cent: ", nickels)
           pennies = amount // 1
           print("1 cent: ", pennies)
The output is way different from expected. Need some guidance on writing the correct calculations, thanks.

Output:
Enter the amount: 47 50 cent: 0 10 cent: 4 5 cent: 9 1 cent: 47
Reply


Messages In This Thread
Need help with coin change program - by Gateux - Jun-24-2019, 01:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Print the frequency of each coin for the combinations that sum to the amount N Pranav 3 2,579 May-19-2020, 06:16 AM
Last Post: Pranav
  Random module, coin flipping gus17 3 4,951 Jan-06-2020, 10:29 AM
Last Post: perfringo
  Adding and Removing coins to match Coin Bag Total infinite times Strayfe 8 4,671 Sep-11-2018, 07:30 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020