萌萌新求助,这里为什么要加一个guess=0
import randomtimes = 3
secret = random.randint(1,10)
print('------------------我爱鱼C工作室------------------')
guess = 0 请问这里的guess=0是什么意思?
print("不妨猜一下小甲鱼现在心里想的是哪个数字:", end=" ")
while (guess != secret) and (times > 0):
temp = input()
if temp.isdigit():
guess = int(temp)
if guess == secret:
print("我草,你是小甲鱼心里的蛔虫吗?!")
print("哼,猜中了也没有奖励!")
else:
if guess > secret:
print("哥,大了大了~~~")
else:
print("嘿,小了,小了~~~")
if times > 1:
print("再试一次吧:", end='')
else:
print("机会用光咯T_T")
else:
print("抱歉,您的输入有误,请输入一个整数:", end='')
times = times - 1
print("游戏结束,不玩啦^_^")
guess = 0
这里加了,后面判断才能用呀
而且第一次 0 绝对不会等于随机数,
本帖最后由 xiaosi4081 于 2020-6-11 07:51 编辑
import random
times = 3
secret = random.randint(1,10)
print('------------------我爱鱼C工作室------------------')
while (guess != secret) and (times > 0):
temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字: ")
if temp.isdigit():
guess = int(temp)
if guess == secret:
print("我草,你是小甲鱼心里的蛔虫吗?!")
print("哼,猜中了也没有奖励!")
else:
if guess > secret:
print("哥,大了大了~~~")
else:
print("嘿,小了,小了~~~")
if times > 1:
print("再试一次吧:", end='')
else:
print("机会用光咯T_T")
times = times - 1
else:
temp = input("抱歉,您的输入有误,请输入一个整数:")
print("游戏结束,不玩啦^_^")
你代码有问题2 初始化变量,后面才能用
页:
[1]