开发者

Python Error:Unindent does not match any outer uindentation limit

开发者 https://www.devze.com 2023-03-11 12:30 出处:网络
As you can see I am a novice in Programming and started with Python, the above said error is occurring on the highlighted line of code.

As you can see I am a novice in Programming and started with Python, the above said error is occurring on the highlighted line of code. How to ride over this...

import random

secret= random.randint (1,100)
guess=0
tries=0

print "AHOY! I am the dead pirate Roberts, and I ahve a secret!"
print  "It is a number from 1 to 99. I will give you six tries."

while guess  !=secret and tries <6:
    guess= input("what's yer guess? " )
    if  guess < secret :
                 print "Too Low, ye curvy dog!"
    elif guess > secret:
                 print "Too high, landlubber!"
                 tries= tries +1

         ***if  guess == secret  :***
             print "Avast! Ye got it! found my secret, ye did!"
                 else:
       开发者_运维知识库      print "No more guesses! Better luck next time, matey!"
             print "The secret number was ", secret" 


Python uses indentation to denote code blocks. The indentation of your code is not valid (the indentation of the if in question doesn't line up with any previous block; from a quick look over the code, there's at least one more error).

The following is a short clear explanation of how indentation works in Python: http://diveintopython.net/getting_to_know_python/indenting_code.html


In python, you must keep a constant indentation between your blocks.

And in the if guess < secret: code block, the indentation is much longer than in the while code block.

The proper code is :

while guess  !=secret and tries <6:
    guess= input("what's yer guess? " )
    if  guess < secret :
        print "Too Low, ye curvy dog!"
    elif guess > secret:
        print "Too high, landlubber!"
        tries= tries +1

    if  guess == secret  :
        print "Avast! Ye got it! found my secret, ye did!"
    else:
        print "No more guesses! Better luck next time, matey!"
        print "The secret number was ", secret" 
0

精彩评论

暂无评论...
验证码 换一张
取 消