标签:python
# import math # print coerce(1L, 134) # """数据类型转换""" # print coerce(0.4, 123) # print coerce(0j, 234) # print divmod(125, 5) # """除法运算""" # print divmod(4, 3) # print pow(2, 4) # """密""" # print round(3) # print round(3.666666, 3) # print round(3.045, 1) # print round(3.7777) # """浮点型四舍五入""" # 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, num2): return num1 * num2 import sys def 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 ** n2 def func6(): num1 = int(raw_input(‘input:‘)) num2 = int(raw_input(‘input:‘)) if num1 % num2 == 0: return True else: return False def func7(): data = raw_input(‘input time:‘) data = data.split(":") hours = int(data[0]) total = hours * 60 + int(data[1]) return total import random def 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 lists print(func8())
本文出自 “xwb” 博客,请务必保留此出处http://xiewb.blog.51cto.com/11091636/1792266
标签:python
原文地址:http://xiewb.blog.51cto.com/11091636/1792266