标签:
Python中的函数主要分为两类,一类是build-in Function(内置函数)例如int(),float(),type(),max()等,另一类是user-define Function(用户自定义函数)
同样以上一节的小例子来说明,计算薪资,如果超过40小时,超过部分就按时薪的1.5倍来算
1 def computepay(h,r): 2 if h > 40 : 3 return 40 * r + (h - 40) * r * 1.5 4 else : 5 return h * r 6 7 hrs = input("Enter Hours:") 8 rate = input("Enter Rate:") 9 try : 10 h = float(hrs) 11 r = float(rate) 12 except : 13 print("please enter a number:") 14 quit() 15 16 p = computepay(h,r) 17 print(p)
标签:
原文地址:http://www.cnblogs.com/wjf0/p/5877159.html