Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help a brother am so new
#1
write a python program that can make change. your program should take two numbers as input, one that is monetary amount charges and the other that is monetary amount given. it should then return the number of each kind of bill and coin to give back as change for the difference between the amount given and the amount charges. the values assigned to the bills and coins can be based on the monetary system of any current or former government. try to design your program so that it returns as few bills and coins as possible.
Reply
#2
we are glad to help you, but we will not write it for you.
please make an effort, show your code, and aks specific question if unable to solve.
Reply
#3
def ChangeMoney(m,n):
    money_type=(20000,10000,5000,2000,1000,500,100,50)
    if m<n:
        print('needs more money to charge!')
        return
    elif m==n:
        print('no need to return money!')
        return
    else:
        result={}
        total=m-n
        for bill in money_type:
            num=total//bill
            result[str(bill)+' FGN']=int(num)
            total=total-num*bill
    print(result)
    
    
ChangeMoney(20000,15000)
Reply
#4
Use meaningful names, single letter names are soon forgotten, and will get you in trouble.
Reply
#5
(Feb-12-2020, 10:09 AM)manimani Wrote:
def ChangeMoney(m,n):
    money_type=(20000,10000,5000,2000,1000,500,100,50)
    if m<n:
        print('needs more money to charge!')
        return
    elif m==n:
        print('no need to return money!')
        return
    else:
        result={}
        total=m-n
        for bill in money_type:
            num=total//bill
            result[str(bill)+' FGN']=int(num)
            total=total-num*bill
    print(result)
    
    
ChangeMoney(20000,15000)
i tried it saved the file at .py but it refused to run on my python
Reply
#6
Ran for me.

Output
{'20000 FGN': 0, '10000 FGN': 0, '5000 FGN': 1, '2000 FGN': 0, '1000 FGN': 0, '500 FGN': 0, '100 FGN': 0, '50 FGN': 0}
You get 1 5000FGN bill back. You'll probably want to print only the Values that a greater than 0 however.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] help a brother am so new MohsinCoding 3 1,805 Feb-14-2020, 12:08 PM
Last Post: MohsinCoding

Forum Jump:

User Panel Messages

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