第004讲改进游戏代码
import randomsecret = random.randint(1,10)
print('......................我爱鱼C工作室......................')
temp = input('不妨猜一下小甲鱼现在心里想的是哪个数字:')
guess = int(temp)
times = 2
while guess !=secret and times !=0:
if guess > secret:
print('哥,大了大了~~~')
temp = input('哎呀,猜错了,请重新输入吧:')
guess = int(temp)
times = times - 1
else:
print('嘿,小了!小了!!')
temp = input('哎呀,猜错了,请重新输入吧:')
guess = int(temp)
times = times - 1
if guess == secret:
print('卧槽,你是小甲鱼心里的蛔虫吗?!')
print('哼,猜中了也没有奖励!')
else:
print('游戏次数用光')
print('游戏结束,不玩啦^_^')
import random
secret = random.randint(1,10)
print('......................我爱鱼C工作室......................')
while True:
try:
temp = int(input('不妨猜一下小甲鱼现在心里想的是哪个数字:'))
break
except ValueError:
print('输入错误,请重新输入1个整数!!!!')
times = 2
while temp !=secret and times !=0:
if temp > secret:
print('哥,大了大了~~~' + '(游戏剩余次数:' + str(times) + ')')
while True:
try:
temp = int(input('哎呀,猜错了,请重新输入吧:'))
break
except ValueError:
print('输入错误,请重新输入1个整数!!!!')
times = times - 1
else:
print('嘿,小了!小了!!' + '(游戏剩余次数:' + str(times) + ')')
while True:
try:
temp = int(input('哎呀,猜错了,请重新输入吧:'))
break
except ValueError:
print('输入错误,请重新输入1个整数!!!!')
times = times - 1
if temp == secret:
print('卧槽,你是小甲鱼心里的蛔虫吗?!')
print('哼,猜中了也没有奖励!')
else:
print('游戏次数用光')
print('游戏结束,不玩啦^_^')
页:
[1]