|
昨天按照《父与子的编程之旅》里面的实例编写,但是总是出错。
import random
secret = random.randint(1,99)
guess=0
tires=0
print "AHOY! i`m the dread print Roberts,and i have a secret!"
print "it`s a nunber form 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 "too low,ye scurvy dog!"
elif guess > sceret:
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 numaber was",secret
F5之后
>>> ================================ RESTART ================================
>>>
AHOY! i`m the dread print Roberts,and i have a secret!
it`s a nunber form 1 to 99.i`ll give you 6 tries
Traceback (most recent call last):
File "E:\My python\学习过程\猜数游戏.py", line 7, in <module>
while guess != secret and tries < 6:
NameError: name 'tries' is not defined
>>>
|
|