为什么这一串code在python2.7里面可以用,但是3.2就不行,求高手帮忙改一下让它在python3.2里面也可以用.
这个是code:importrandomnum=random.randint(1,100)guesses=1while1:guess=input("EnterYourGu...
这个是code:import random
num = random.randint(1,100)
guesses = 1
while 1:
guess = input("Enter Your Guess ")
if guess == num: break
elif guess > num:
print "Lower"
guesses = guesses+1
elif num > guess:
print "Higher"
guesses = guesses+1
guesses = str(guesses)
print "You Win. It took you "+guesses+" guesses."
raw_input 展开
num = random.randint(1,100)
guesses = 1
while 1:
guess = input("Enter Your Guess ")
if guess == num: break
elif guess > num:
print "Lower"
guesses = guesses+1
elif num > guess:
print "Higher"
guesses = guesses+1
guesses = str(guesses)
print "You Win. It took you "+guesses+" guesses."
raw_input 展开
1个回答
2013-07-08
展开全部
python2 和3已经不兼容了,最明显的就是python2中的print,在3里面必须用print(),就这一点,你上面的代码就没法用,python2提供了2to3的工具,用它转一下就行了,其实大部分语法还是一样的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询