else & elif statements not working in Python

后端 未结 9 1039
礼貌的吻别
礼貌的吻别 2020-12-10 11:06

I\'m a newbie to Python and currently learning Control Flow commands like if, else, etc.

The if statement is working all fine

9条回答
  •  悲&欢浪女
    2020-12-10 11:49

    It looks like you are entering a blank line after the body of the if statement. This is a cue to the interactive compiler that you are done with the block entirely, so it is not expecting any elif/else blocks. Try entering the code exactly like this, and only hit enter once after each line:

    if guess == number:
        print('Congratulations! You guessed it.')
    elif guess < number:
        pass # Your code here
    else:
        pass # Your code here
    

提交回复
热议问题