python3.4.2里的程序执行问题
importrandomsecret=random.randint(1,100)guess=0tries=0print("这是一个猜数字游戏!")print("数字是1到...
import random
secret = random.randint(1,100)
guess = 0
tries = 0
print("这是一个猜数字游戏!")
print ("数字是1到99,你有六次机会!")
while guess != secret and tries < 6:
guess = input("请输入数字?")
if guess < secret:
print ("数字太小...!")
elif guess >secret:
print ("数字太大...")
elif guess == secret:
print ("恭喜你猜对了!")
tries = tries +1
if tries==6:
print ("你6次机会用完了...")
print ("正确的数字是"),secret
break
非常精典的猜数字,问题是哪错了?怎么在3.4.2运行不了啊?! 展开
secret = random.randint(1,100)
guess = 0
tries = 0
print("这是一个猜数字游戏!")
print ("数字是1到99,你有六次机会!")
while guess != secret and tries < 6:
guess = input("请输入数字?")
if guess < secret:
print ("数字太小...!")
elif guess >secret:
print ("数字太大...")
elif guess == secret:
print ("恭喜你猜对了!")
tries = tries +1
if tries==6:
print ("你6次机会用完了...")
print ("正确的数字是"),secret
break
非常精典的猜数字,问题是哪错了?怎么在3.4.2运行不了啊?! 展开
1个回答
展开全部
import random
secret = random.randint(1,100)
guess = 0
tries = 0
print("这是一个猜数字游戏!")
print ("数字是1到99,你有六次机会!")
while guess != secret and tries < 6:
guess = int(input("请输入数字?")) #python3中input返回字符串,转换为整数
if guess < secret:
print ("数字太小...!")
elif guess >secret:
print ("数字太大...")
elif guess == secret:
print ("恭喜你猜对了!")
break #猜对了退出,tries<6已经在while条件中做了判断,不要在最后用if重复判断
tries = tries +1
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询