<<Python编程实践>>之Choose
来源:互联网 发布:java 网络框架 编辑:程序博客网 时间:2024/06/08 13:01
#!/usr/bin/python#encoding:utf8#ph值判别程序print "Please input a ph value: "def phchoose(ph):'''ph value and choose acidic or basic'''if ph < 7.0: print "ph value %s is acidic." % phelif ph > 7.0:print "ph value %s is basic." % phelse:print "ph value %s is neutral." % phph = float(raw_input())phchoose(ph)#年龄体重指数和患心脏病的关系#---------------年龄---#------------< 45 >=45#体重< 22.0 低 中#指数>=22.0 中 高#method_1def method1(age,bmi):if age < 45:if bmi < 22.0:return 'risk = low'else: return 'risk = medium'else:if bmi < 22.0:return 'risk = medium'else:return 'risk = high'print "Please input age and bmi: "age = int(raw_input())bmi = float(raw_input())print "Age %d Bmi %s" % (age,bmi),risk = method1(age,bmi)print risk#method_2def method2(age,bmi):young = age < 45slim = bmi < 22.0if young:if slim:return 'risk = low'else:return 'risk = medium'else:if slim:return 'risk = medium'else:return 'risk = high'risk2 = method2(age,bmi)print 'method2 : ', risk2#method_3def method3(age,bmi):young = age < 45slim = bmi < 22.0if young and slim:return 'risk = low'elif young and not slim:return 'risk = medium'elif not young and slim:return 'risk = medium'elif not young and not slim:return 'risk = high'risk3 = method3(age,bmi)print 'method3 : ',risk3#mehtod_4young = age < 45heavy = bmi >= 22.0table = [['medium','high'],['low','medium']]risk = table[young][heavy]print 'method4 : risk =',risk
0 0
- <<Python编程实践>>之Choose
- <<Python编程实践>>之FileListTuple
- <<Python编程实践>>之WhileBreakContinue
- <<Python编程实践>>之which is __main__
- python 实践之 ctypes
- python之print实践
- 极限编程之实践
- Python函数式编程实践
- Python多核编程mpi4py实践
- python编程与实践读书笔记
- Python学习(1)--《Python编程实践》
- FP编程实践:在C++0x中模拟F#的List.map和List.choose库函数
- Python之IPython开发实践
- JavaScript提高效率之编程实践
- Python实践之网络编程1-简单的网络请求程序
- 我的人工智能之路1-Python编程:从入门到实践-1
- 我的人工智能之路1-Python编程:从入门到实践-2
- 【Python】Python 日志实践之logging模块
- 设计模式之访问者模式(Visitor)摘录
- EC2菜鸟入门日记之一(登陆与验货)
- Eclipse下编写C++程序——CDT环境搭建
- 从上往下打印二叉树(面试题 23)
- linux学习笔记1
- <<Python编程实践>>之Choose
- 腾讯应用中的轩辕诀这款游戏好玩不?轩辕诀游戏介绍
- leetcode: String to Integer (atoi)
- POLYA合集 II
- 哈夫曼树
- 学习总结四:hadoop集群动态增加新节点及下架一个节点
- hibernate数据类型,标准sql数据类型之间的对应表
- mysqldump的使用
- 超级演说家