为什么这一串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
展开
展开全部
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()
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()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询