码迷,mamicode.com
首页 > 编程语言 > 详细

Python中的函数

时间:2016-09-16 21:13:52      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

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)

 

Python中的函数

标签:

原文地址:http://www.cnblogs.com/wjf0/p/5877159.html

(0)
(3)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!