Python implements a small program code sharing, python change
The Python program looks for change at the nominal value. It uses our normal thinking logic to find a change from a large nominal value to a small nominal value. The RMB nominal value is 100 yuan, 50 yuan, and 20 yuan, 10 yuan, 5 yuan, 1 yuan, 5 angles, 1 angle, and the program also sets these denominations. You only need to input the amount you want to find when calling the function. The program will automatically calculate the amount of money for each nominal value. For example, if 50 yuan is input, the system automatically calculates the value of 50 yuan. If 60 yuan is input, the program automatically calculates the value of 50 yuan, 10 yuan, and 5 cents, one or two images.
# Encoding = UTF-8 def zhaoqian (money): loop = True tmp = ['total amount: '+ str (money) + 'meta'] # nominal value list unit: yuan cate = (100, 50, 20, 10, 5, 1, 0.5, 0.1) sy = int (money * 10) while loop: if sy = 0: loop = False else: for row in cate: tmpStr = ''jine = int (row * 10) if jine> = 10: tmpUn = 'yuan' else: tmpUn = 'core' if sy> = jine and tmpStr = '': m = sy // jine sy = sy % jine if jine> = 10: tmpStr = str (jine // 10) + tmpUn + str (m) + 'zhang' else: tmpStr = str (jine) + tmpUn + str (m) + 'zhang 'tmp. append (tmpStr) return tmp a = zhaoqian (88.7) for x in a: print x
Compile a small program in python
#-*-Coding: UTF-8 -*-
"""
Created on Tue May 14 08:32:47 2013
@ Author: Administrator
"""
Import urllib2
Import re
Def savetofile (num, count ):
File_object = open('thefile.txt ', 'a + ')
Line = str (num) + ''+ count [0] + '\ N'
File_object.write (line)
File_object.close ()
Def geturl (url, num ):
Searchurl = url + str (num)
Print searchurl,
Data = urllib2.urlopen (searchurl)
Html = data. read ()
Data. close ()
# Print html
Rebaidu = re. compile (r'baidu finds related results for you (.*?) ')
Allbaidu = re. findall (rebaidu, html)
# Print allbaidu
Savetofile (num, allbaidu)
If _ name __= = '_ main __':
For x in xrange (100 ):
Geturl ('www .baidu.com/s? Wd = ', x)
Python applet code trainer
Email to me, private chat to you