代碼如下: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運(yùn)行錯(cuò)誤提示:Traceback (most recent call last): File "C:/Users/whisk/Desktop/編程學(xué)習(xí)/list.1-2.py", line 7, in <module> while guess != secret and tries < 6:NameError: name 'guess' is not defined是根據(jù)書籍《父與子的編程之旅》學(xué)習(xí)的,剛開始,對(duì)照了書上和自己寫的代碼,并沒有拼寫錯(cuò)誤,希望有大神點(diǎn)一下,謝謝。
新手之路:代碼定義錯(cuò)誤
阿晨1998
2018-07-16 11:20:21