为什么这一串code在python2.7里面可以用,但是3.2就不行,求高手帮忙改一下让它在python3.2里面也可以用.

这个是code:importrandomnum=random.randint(1,100)guesses=1while1:   guess=... 这个是code:import randomnum = random.randint(1,100)guesses = 1while 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+1guesses = str(guesses)print "You Win. It took you "+guesses+" guesses."raw_input 展开
 我来答
lix_xu
2011-11-19 · TA获得超过1213个赞
知道小有建树答主
回答量:823
采纳率:0%
帮助的人:697万
展开全部
1. print在Python3里已经变成函数
2. input()在python2里如果输入数字会自动转成整数, 在Python3里是字符串

import random
num = random.randint(1,100)
guesses = 1
while 1:
guess = int(raw_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()
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式