<<Python编程实践>>之WhileBreakContinue
来源:互联网 发布:数据库管理系统教程 编辑:程序博客网 时间:2024/06/14 09:53
#!user/bin/python#encoding:utf8#whiletime = 0population = 1000 # 1000 bacteria to start withgrow_rate = 0.21 # 21% growth per minutewhile population < 2000:population = population + grow_rate * populationprint populationtime = time + 1print "It took %d minutes for the bacteria to double." % timeprint "...and the final population was %6.2f bacteria." % populationtext = ' 'while text != "quit":text = raw_input("Please enter a chemical formula (or 'quit' to exit): ")if text == "quit":print "...exiting program."elif text == "H2O":print "Water"elif text == "NH3":print "Ammonia"elif text == "CH3":print "Methane"else:print "Unknown compound"#breakearth_line = 1file = open("data.txt","r")for line in file:line = line.strip()if line == "Earth":breakearth_line += 1print "Earth is at the line %d" % earth_linefile.close()#continueentry_number = 1file = open("data.txt","r")for line in file:line = line.strip()if line.startswith('#'):continueif line == "Earth":breakentry_number += 1print "Earth is the %dth-lightest planet." % entry_number
0 0
- <<Python编程实践>>之WhileBreakContinue
- <<Python编程实践>>之Choose
- <<Python编程实践>>之FileListTuple
- <<Python编程实践>>之which is __main__
- python 实践之 ctypes
- python之print实践
- 极限编程之实践
- Python函数式编程实践
- Python多核编程mpi4py实践
- python编程与实践读书笔记
- Python学习(1)--《Python编程实践》
- Python之IPython开发实践
- JavaScript提高效率之编程实践
- Python实践之网络编程1-简单的网络请求程序
- 我的人工智能之路1-Python编程:从入门到实践-1
- 我的人工智能之路1-Python编程:从入门到实践-2
- 【Python】Python 日志实践之logging模块
- 《Python编程实践》查漏笔记
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- HDU2457 DNA repair
- btgfc
- hibernate注解配置
- 每一个程序员必须掌握的知识,字符集与字符编码.
- <<Python编程实践>>之WhileBreakContinue
- Ckeditor结合springmvc的使用、配置、上传图片、分页
- java_图片验证码生成-
- 梯度下降算法详解
- LeetCode OJ - Combinations
- 你只负责过程的努力;结果和未来的安排,是上帝负责的事情
- throw和throws子句的区别
- 如何查看现有项目的struts和hibernate和spring版本
- 【HDU】3341 Lost's revenge AC自动机+变进制+DP