|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random
times = 3
secret = random.randint(1,10)
print('------------------我爱鱼C工作室------------------')
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 # 用户每输入一次,可用机会就-1
print("游戏结束,不玩啦^_^")
本帖最后由 sunrise085 于 2020-9-14 16:06 编辑
times=times-1 这一行需要缩进,它是while循环内的一句
- import random
- times = 3
- secret = random .randint (1,10)
- print('`````````我爱鱼C工作室`````````````')
- 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('机会用光咯')
-
- else:
- print('抱歉,你的输入有误,请输入一个整数:',end='')
-
- times = times - 1 #这一行需要缩进
- print('游戏结束了,不玩了')
复制代码
|
|