|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 tianalng233 于 2017-2-13 09:33 编辑
首先是题目:
其次是代码:- i = 1
- test1 = (i%2 == 1)
- test2 = (i%3 == 2)
- test3 = (i%5 == 4)
- test4 = (i%6 == 5)
- test5 = (i%7 == 0)
- test = test1 and test2 and test3 and tes4 and test5
- while not test:
- i += 1
- print(i)
- print(i)
复制代码
最后是运行结果:运行结果是一个死循环.
如图:
运行结果是强行停止的.然后我找到的原因可能是由于 这一部分代码的问题.
- test1 = (i%2 == 1)
- test2 = (i%3 == 2)
- test3 = (i%5 == 4)
- test4 = (i%6 == 5)
- test5 = (i%7 == 0)
- test = test1 and test2 and test3 and tes4 and test5
- while not test:
-
复制代码
导致test永远为False,从而一直是死循环
我就想问一下,我的这串代码到底是为什么错的.
并且,我在python3的命令行中运行
这个又没有问题,那就说明test = test1 and test2 这种形式是正确的.
问题就是这个test 判断语句,根本没有和循环体一起进行重复判断,所以test值只进行第一次判断,之后始终为假,也就只能一直输出所有数字。
这方式不可行。
具体你再比对下前辈的方法。
|
|