繁体   English   中英

IndentationError:预期在可变扫描时间生成python错误中的缩进块

[英]IndentationError: expected an indented block in python error generate at variable scan time

这是我的代码,实际上我只想使用infinite while循环来扫描一些int值,并执行比较以了解是否正确的guass数,但是它不起作用给我有关“ indentationError的错误:期望缩进块”

running = True
while running:
guess = int(input('Enter an integer : '))
if guess == number:
print 'Congratulations, you guessed it.'
# this causes the while loop to stop
running = False
elif guess < number:
print 'No, it is a little higher than that.'
else:
print 'No, it is a little lower than that.'
else:
print 'The while loop is over.'
# Do anything else you want to do here
print 'Done'

许多语言使用花括号来封装条件表达式,函数,类等的分支。Python使用空格代替。 这是您的代码的正确格式:

running = True
while running:
    guess = int(input('Enter an integer : '))
    if guess == number:
        print 'Congratulations, you guessed it.'
        # this causes the while loop to stop
        running = False
    elif guess < number:
        print 'No, it is a little higher than that.'
    else:
        print 'No, it is a little lower than that.'
else:
    print 'The while loop is over.'

# Do anything else you want to do here
print 'Done'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM