|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random
times = 3
x = random.randint(1,10)
print('---------猜数字小游戏---------')
temp = input('猜猜看现在是1-10之间的什么数字:')
guess = int(temp)
while guess != x and times > 0:
times -= 1
if guess > 10 or guess < 0 :
print('请输入规格内的数字。')
temp = input('请继续输入吧:')
guess = int(temp)
else:
if guess > x and times != 0:
print('呀,大啦!')
print('再想一下吧')
temp = input('请继续输入吧:')
guess = int(temp)
else:
print('嘿,小啦!')
print('真笨!')
temp = input('请重新输入吧:')
guess = int(temp)
while guess != x and times == 0:
print('次数用完咯。')
break
else:
print('猜对啦')
break
print ('好啦,不玩啦!')
本帖最后由 Twilight6 于 2020-6-11 21:35 编辑
小小改动下~
- import random
- times = 3
- x = random.randint(1,10)
- print('---------猜数字小游戏---------')
- temp = input('猜猜看现在是1-10之间的什么数字:')
- guess = int(temp)
- while guess != x and times > 0:
- if guess > 10 or guess < 0 :
- print('请输入规格内的数字。')
- temp = input('请继续输入吧:')
- guess = int(temp)
- else:
- times -= 1
- if times == 0 and guess != x:
- print('哎呀,还是错了!正确答案是:',x,'你的次数用完咯。')
- break
- if guess > x :
- print('呀,大啦!')
- print('再想一下吧')
- temp = input('请继续输入吧:')
- guess = int(temp)
- else:
- print('嘿,小啦!')
- print('真笨!')
- temp = input('请重新输入吧:')
- guess = int(temp)
- if guess == x:
- print('恭喜你!答对啦~~')
- print ('好啦,不玩啦!')
复制代码
|
-
|