Python零基础学习 问题及作业 问题待续
2018-03-05 16:19
344 查看
先上问题:input BIF
看下面这段代码,无论怎么测试都退不出循环,很郁闷print('=-------------闰年计算器-------------=') print('注意:输入查询的年份,格式:XXXX,如2014') temp = 1 while temp != 110: temp = input('请输入查询的年份: ') while temp.isdigit() != 1: temp = input('对不起,输入格式为正数!重新输入:') year = int(temp) if year / 400 == int(year / 400): print('公元', temp, '年是闰年!') else: if (year / 4 == int(year / 4)) and (year / 100 == int(year / 100)): print('公元', temp, '年是闰年!') else: print('公元', temp, '年是平年!') print('GameOver')
为了方便测试,简化一下代码
temp = 0 while temp != 520: temp = input('enter a number:') print(temp)
结果是这样的:
enter a number:520
520
enter a number:520
520
enter a number:520
520
enter a number:
想办法解决,查看 while 和 input 两个BIF
>>> help(input)
Help on built-in function input in module builtins:
input(prompt=None, /)
Read a string from standard input. The trailing newline is stripped.The prompt string, if given, is printed to standard output without a trailing newline before reading input.
哎呀我去,
input-read a string from standard input
update code
temp = 0 while temp != '520': temp = input('enter a number:') print(temp)
print('=-------------闰年计算器-------------=') print('注意:输入查询的年份,格式:XXXX,如2014') temp = 1 while temp != '110': temp = input('请输入查询的年份: ') while temp.isdigit() != 1: temp = input('对不起,输入格式为正数!重新输入:') year = int(temp) if year / 400 == int(year / 400): print('公元', temp, '年是闰年!') else: if (year / 4 == int(year / 4)) and (year / 100 == int(year / 100)): print('公元', temp, '年是闰年!') else: print('公元', temp, '年是平年!') print('GameOver')
总结:BIF使用时,一定要注意
相关文章推荐
- Python初学者(零基础学习Python、Python入门)常见问题:书籍推荐、资料、社区
- 删除列表元素时需注意的问题 分类: python基础学习 python 小练习 2013-10-09 14:02 293人阅读 评论(0) 收藏
- 零基础学习Python 作业 第1章
- python学习(一)---基础知识(安装、IDE、API查询、常见问题)
- 零基础学习Python 作业 第5章
- 学习python基础语法中遇到的一些问题
- MySQL问题解决:-bash:mysql:command not found 分类: ubuntu 问题总结 python基础学习 software database 2014-01-22 16:00 3088人阅读 评论(1) 收藏
- 零基础学习Python 作业 第10章
- 零基础学习Python 作业 第15章
- 零基础学习Python 作业 第3章
- 零基础学习Python 作业 第16章
- Python初学者(零基础学习Python、Python入门)常见问题:书籍推荐、资料、社区
- 零基础学习Python 作业 第11-12章
- 零基础学习Python 作业 第6章
- python基础学习二:python编码问题:
- 零基础学习Python 作业 第13章
- 安装pip 分类: ubuntu python基础学习 python Module software 问题总结 2014-02-19 09:16 229人阅读 评论(0) 收藏
- 零基础学习Python 作业 第7-8章
- Python初学者(零基础学习Python、Python入门)常见问题:书籍推荐、资料、社区
- Python基础学习(5)网络编程socket、文件上传、粘包问题、socketserver、IO多路复用、线程与进程、进程池、线程池、上下文管理、协程