代碼如下:import randomsecret = random.randint(1,99)gurss = 0tries = 0print "AHOY! I'm the Dread Pirate Roberts, and I have a secret!"print "It is a number from 1 to 99. I'll give you 6 tries."while guess != secret and tries < 6: guess = input ("What's yer guess?") if guess < secret: print "Two low,ye scurvy dog!" elif guess > secret: print "Two high,landubber!" tries = tries + 1if 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運行錯誤提示:Traceback (most recent call last): File "C:/Users/whisk/Desktop/編程學習/list.1-2.py", line 7, in <module> while guess != secret and tries < 6:NameError: name 'guess' is not defined是根據書籍《父與子的編程之旅》學習的,剛開始,對照了書上和自己寫的代碼,并沒有拼寫錯誤,希望有大神點一下,謝謝。
新手之路:代碼定義錯誤
阿晨1998
2018-07-16 11:20:21