早教吧 育儿知识 作业答案 考试题库 百科 知识分享

python2.5与python3.2有什么区别importrandomsecret=random.randint(1,100)guess=0tries=0print("ahoy!I'mthedreadpirate,andihaveasecret!")print("itisanumberfrom1to99.i'11giveyou6tries.")whileguess=secretandtriessecret:p

题目详情
python2.5与python3.2有什么区别
import random
secret = random.randint(1,100)
guess = 0
tries = 0
print ("ahoy!I'm the dread pirate,and i have a secret!")
print ("it is a number from 1to 99.i'11 give you 6 tries.")
while guess =secret and tries secret:
print ("too high,landlubber!")
tries = tries + 1
if guess == secret:
print ("avast!ye got it!gound my secret,ye did!")
else:
print ("no more guesses!butter luck next time,matey!")
print ("the secret numbei wad"),secret
这个在3.2里怎么运行不了
▼优质解答
答案和解析
guess = 20, input("what's yer guess?")
这里是相当于把一个 tuple 赋给 guess
所以执行if guess < secret: 认为两端类型不匹配.
最后一句:
print ("the secret numbei wad"), secret
print 只会打印出括号中的信息,括号外的数据是不会打印的