# import math# print coerce (1l, 134) # "" "Data type Conversion" "" # print coerce (0.4, 123) # print coerce (0j, 234) # print divmod (125, 5) # "" "Division Operation" "# Print divmod (4, 3) # print pow (2, 4) # "" "Secret" "# print round (3) # Print round (3.666666, 3) # print round (3.045, 1) # print round (3.7777) # "" "floating-point rounding" "" # for i in range (5): # print round (Math.PI, i) "" for eachnum in (.2, 0.7, 1.2, 1.7, -.2, -0.7, -1.2, -1.7): print "int (%0.1f) \t+%0. 1f % (Eachnum, int (eachnum)) print floor (%0.1f) \t+%0.1f % (Eachnum, math.floor (eachnum)) print "Round (%0.1f) \t+%0.1f" % (Eachnum, round (eachnum)) print "-" * 20 "" "Def func1 ( NUM1,&NBSP;NUM2): return num1 * num2import sysdef func2 (): num = int (Raw_input (' Input your number: ')) if (num >= 90) and (num <= 100): return "a:90~100" elif (num >= 80) and ( num <= 89): return "B:80~89" elif (num >= 70) and (num <= 79): return "c:70~79" elif (num >= 60) and (num <= 69): return "D:60~69" elif 0 <= num < 60: return "F:0~60" else: sys.exit () def func3 (): year = int (Raw_input (' input your year: ')) if (year % 4 == 0) and (year % 100 != 0) or ( year % 4 == 0) and (year % 100 == 0): return '%d yun year ' % year else : return '%d is not yun year ' % year sys.exit () Def func4 (): Result = [] number = int (Raw_input (' Input your number: ')) meifen = [25, 10, 5, 1] for i in meifen: result.append (number/i) number = number % i return "25 cert is %d , 10 cert is %d,5 cert is %d,1 cert is %d " % (Result[0], result[1], result[2], result [3]) Def func5 (): oper = ["*", "-", "+", "/", "%", " * * "] exp = raw_input (' input exp: ') for op in oper: if exp.find (OP) > -1 and exp.count (OP) < 2: numbers = exp.split (OP) lists = [] for i in numbers: Lists.append (i) n1 = int ( Lists[0]) i = op n2 = int (lists[1]) if i == "*": return n1 * n2 elif i == "-": return n1 - n2 elif i == "+": return n1 * n2 elif i == "/": return n1 / n2 elif i == "%": return n1 % n2 elif i == "* *": return n1 ** n2def func6 (): num1 = int (raw_input (' Input: ')) num2 = int (Raw_input (' Input: ') if num1 % num2 == 0: return True else: return falsedef func7 (): data = raw_input (' input time: ') data = data.split (":") hours = int (Data[0]) total&nbsP;= hours * 60 + int (data[1]) return totalimport Randomdef func8 (): rand = random.randint (1, 100) lists = [] for i in range (Rand): brand = random.randint (0, (POW (2, 31) - 1)) lists.append (Brand) lists.sort () return listsprint (Func8 ())
This article is from the "XWB" blog, make sure to keep this source http://xiewb.blog.51cto.com/11091636/1792266
Python Basic Learning Code numbers