number=33
for i in range(3):
while i:
guess=int(input('Enter an integer :'))
if guess==number:
print('Congratulations, you guessed it.')
print('(but you do not win any prizes!)')
break
elif guess<=number-5:
print('No, it is a little higher than that')
elif abs(guess-number)<5:
print('很接近了!')
else:
print('No, it is a little lower than that')
else:
print('test')
print('Done')
------------------------------------------------------------
第一次执行什么参数都没输入为什么会执行>>print('test')
>>print('test')的缩进级别与 while 一致
for i in range(3):
while i:
guess=int(input('Enter an integer :'))
if guess==number:
print('Congratulations, you guessed it.')
print('(but you do not win any prizes!)')
break
elif guess<=number-5:
print('No, it is a little higher than that')
elif abs(guess-number)<5:
print('很接近了!')
else:
print('No, it is a little lower than that')
else:
print('test')
print('Done')
------------------------------------------------------------
第一次执行什么参数都没输入为什么会执行>>print('test')
>>print('test')的缩进级别与 while 一致
13 条回复 • 2018-12-08 13:37:35 +08:00
|
1
ballshapesdsd 2018 年 12 月 8 日
|
|
2
longbye0 2018 年 12 月 8 日 via Android 代码不是这样贴的啊。
关键字,循环语句 else,百度下? |
|
3
zxcvsh 2018 年 12 月 8 日 via iPhone
难得你还知道补一句
缩进 |
|
4
bpllzbh 2018 年 12 月 8 日
你让我怎么面向游标卡尺编程
|
|
5
zyc233 OP @longbye0 我有百度过,答案都不是我想要的,我把最后一个[else 的缩进级别提升到 for]&[从 1 开始 for]就不会出现这种情况;就是不太明白为什么 0 就会先执行与 while 缩进级别一致的 else
|
|
7
Erichailong 2018 年 12 月 8 日 via Android
建议撤了,重新贴代码
|
|
8
ballshapesdsd 2018 年 12 月 8 日
while i 是啥,是 while 1 么?
|
|
9
Depth 2018 年 12 月 8 日 |
|
10
zyc233 OP @ballshapesdsd while 变量 i (字母 i)
|
|
12
Hzzone 2018 年 12 月 8 日
....
|
推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide