【Python】Learn Python the hard way, ex21 函数返回值return
来源:互联网 发布:淘宝app我是商家 编辑:程序博客网 时间:2024/06/07 11:11
def add(a, b): print "ADDING %d + %d" % (a, b) return a + b def subtract(a, b): print "SUBTRACTING %d - %d" % (a, b) return a - b def multiply(a, b): print "MULTIPLYING %d * %d" % (a, b) return a * b def divide(a, b): print "DIVIDING %d / %d" % (a, b) return a / b print "Let's do some math with just functions!"age = add(30, 5)height = subtract(78, 4)weight = multiply(90, 2)iq = divide(100, 2)print "Age: %d, Height: %d, Weight: %d, IQ: %d" % (age, height, weight, iq)# A puzzle for the extra credit, type it in anyway.print "Here is a puzzle."what = add(age, subtract(height, multiply(weight, divide(iq, 2))))print "That becomes: ", what, "Can you do it by hand?"'''Test Result:Let's do some math with just functions!ADDING 30 + 5SUBTRACTING 78 - 4MULTIPLYING 90 * 2DIVIDING 100 / 2Age: 35, Height: 74, Weight: 180, IQ: 50Here is a puzzle.DIVIDING 50 / 2MULTIPLYING 180 * 25SUBTRACTING 74 - 4500ADDING 35 + -4426That becomes: -4391 Can you do it by hand?'''
0 0
- 【Python】Learn Python the hard way, ex21 函数返回值return
- Learn Python The Hard Way
- Learn Python The Hard Way
- 【Python】Learn Python the hard way, ex18 def函数
- 【Python】Learn Python the hard way, ex19 函数和变量
- 【Python】Learn Python the hard way, ex24 函数综合练习
- 【Python】Learn Python the hard way, ex25 函数综合练习
- Learn Python The Hard Way学习(21) - 函数可以返回信息
- 函数可以返回某些东西。习题21---learn python the hard way.
- Learn Python The Hard Way学习(19) - 函数和变量
- Learn Python The Hard Way学习(20) - 函数和文件
- Learn Python The Hard Way学习(35) - 分支和函数
- 函数与文件-习题20--learn python the hard way
- Learn Python the Hard Way ex48
- 学《learn python the hard way》(3)
- learn python the hard way 的ex48
- Learn Python The Hard Way-Ecercise1~5
- Learn Python The Hard Way-Ecercise6~10
- 黑马程序员——OC基础---分类(Category)、非正式协议及分类延展
- 封装、继承、多态的再次理解
- 数据挖掘导论学习笔记之分类基本概念、决策树与模型评估
- 如何区分 const char * p, char * const p, const char * * p?
- 【UML】部署图Deployment diagram(实现图)
- 【Python】Learn Python the hard way, ex21 函数返回值return
- watchOS开发——配置静态通知界面和动态通知界面
- Android音频系统之AudioFlinger(一)
- PreparedStatement和Statement
- jQuery知识点总结
- 忽略大小写比较字符串大小
- listview
- rangeOfString 失效了
- unityscript OnGUI无法生成GUI界面。