简体   繁体   中英

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

here is my code actually i want to just use the infinite while loop to scan some int value and perform a compare if to find out the guass number is correct or not but it doesn't work give me the error about " indentationError: expected an indented block"

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'

Many languages use braces to to encapsulate branches of conditional expressions, functions, classes, etc. Python uses whitespace to do this instead. Here is the correct formatting for your code:

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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