Python作业之:猜数游戏

import random  #随机函数
secret = random.randint(1,10) #secret 取1到10随机数
print("猜数游戏" .center(50,"-"))
times = 3
guess = 0
# print("不妨猜一下我现在心里想的是哪一个数字:",end="")
# print("不妨猜一下我现在心里想的是哪一个数字:")
while (guess != secret)and(times > 0):
team = input("不妨猜一下我现在心里想的是哪一个数字:")
guess = int(team)
times -=1
if guess == secret:
print("你是我肚子里的蛔虫吗?\n猜对了也没有奖励的哈哈!")
else:
if guess > secret:
print("大了,大了兄弟.")
else:
print("小了,小了笨蛋.")
if times > 0:
# print("再试一次吧笨蛋",end="")
print("再试一次吧笨蛋!")
else:
print("机会用光了噢噢_@_")
print("game over,goodbye!")





升级版:
import random  #随机函数
secret = random.randint(1,10) #secret 取1到10随机数
print("猜数游戏" .center(50,"-"))
times = 3
guess = 0
print("不妨猜一下我现在心里想的是哪一个数字?",end='')
while (guess != secret) and (times > 0):
team = input("请输入一个数字:")
while not team.isdigit():
print("抱歉,输入不合法,", end='')
team = input("请重新输入一个数字:")
guess = int(team)
times -= 1
if guess == secret:
print("你是我肚子里的蛔虫吗?\n猜对了也没有奖励的哈哈!")
else:
if guess > secret:
print("大了,大了兄弟.")
else:
print("小了,小了笨蛋.")
if times > 0:
# print("再试一次吧笨蛋",end="")
print("再试一次吧笨蛋!")
else:
print("机会用光了噢噢_@_")
print("game over,goodbye!")

代码摘至:鱼C论坛课后作业

转载于:https://www.cnblogs.com/ouwen/p/7201395.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值