请教下各位:
我用的版本是python2.7.8,运行与孩子一起学编程书中猜数游戏的代码是出错
提示如下
Traceback (most recent call last):
File "D:/工作/数据分析/Python/练习/NumGuess", line 16, in <module>
tries=tires+1
NameError: name 'tires' is not defined
下面是我的代码,其中global 两句是我百度之后加上的,加上之后运行仍然不对,不知道是不是版本差异问题,请教各位,应该是如何写
import random
global tries
global guess
secret =random.randint(1,100)
guess =0
tries =0
print "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 tires."
while guess!=secret and tries <6:
guess=input("What's your guess? ")
if guess<secret:
print "Too low,ye scurvy dog!"
elif guess > secret:
print "Too high,Landlubber!"
tries=tires + 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 secre number was ",secret
import random
global tries
global guess
secret =random.randint(1,100)
guess =0
tries =0
print "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 tires."
while guess!=secret and tries <6:
guess=input("What's your guess? ")
if guess<secret:
print "Too low,ye scurvy dog!"
elif guess > secret:
print "Too high,Landlubber!"
tries=tires + 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 secre number was ",secret