Python Forum
help a brother am so new - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: help a brother am so new (/thread-24393.html)



help a brother am so new - manimani - Feb-12-2020

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.


RE: help a brother am so new - Larz60+ - Feb-12-2020

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.


RE: help a brother am so new - manimani - Feb-12-2020

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)



RE: help a brother am so new - Larz60+ - Feb-12-2020

Use meaningful names, single letter names are soon forgotten, and will get you in trouble.


RE: help a brother am so new - manimani - Feb-14-2020

(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


RE: help a brother am so new - michael1789 - Feb-14-2020

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.