Python implementation of a small change program code sharing

  • 2020-04-02 14:01:04
  • OfStack

Python wrote a program to get change according to the face value, according to our normal thinking logic from the large to small face value of the change method, the face value of RMB has 100 yuan, 50 yuan, 20 yuan, 10 yuan, 5 yuan, 1 yuan, 5 jiao, 1 jiao, and the program also set these face value accordingly. Simply pass in the amount of change you want when you call the function, and the program automatically calculates how many bills of each denomination should be found. If 50 yuan is passed in, the system will automatically calculate the change of 50 yuan a face value, if 60 yuan 7 cents, the program will automatically calculate the change of 50 yuan a, 10 yuan a, 5 jiao a, 1 jiao two.

# encoding=UTF-8
def zhaoqian(money):
    tmp=[' Total amount: '+str(money)+' yuan ']
    #  Face value list   Unit: 
    while loop:
        if sy==0:
            for row in cate:
                tmpStr = ''
                if jine>=10:
                    tmpUn = ' yuan '
                    tmpUn = ' Angle '
                if sy>=jine and tmpStr=='':
                    m = sy//jine
                    sy = sy%jine
                    if jine>=10:
                        tmpStr = str(jine//10) + tmpUn + STR (m) + 'a'
                        tmpStr = str(jine)+tmpUn+str(m)+' zhang '
    return tmp
for x in a:
    print x

Related articles: