|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random
secret = random.randint(1,10)
game=input("guess a number from 0~10 :")
n=1
while n!=0:
if game.isdigit():
guess=int(game)
if guess == secret:
print("wow,you can really dance!")
while guess !=secret and n < 4:
game=input("try again:")
guess=int(game)
if guess == secret:
print("wow,you can really dance!")
if guess > secret:
print("nonono,too loud!")
n=n+1
if guess < secret:
print("you should put more in")
n=n+1
else:
print("抱歉,您的输入有误,请输入一个整数:", end='')
print("game over...")
本帖最后由 青出于蓝 于 2021-7-15 21:39 编辑
- import random
- secret = random.randint(1,10)
- game=input("guess a number from 0~10 :")
- n=1
- while n!=0:
- if game.isdigit():
- guess=int(game)
- if guess == secret:
- print("wow,you can really dance!")
- while guess !=secret and n < 4:
- game=input("try again:")
- guess=int(game)
- if guess == secret:
- print("wow,you can really dance!")
- if guess > secret:
- print("nonono,too loud!")
- n=n+1
- if guess < secret:
- print("you should put more in")
- n=n+1
- else:
- print("抱歉,您的输入有误,请输入一个整数:", end='')
- break
- print("game over...")
复制代码
输入错误也要break停止循环
缩进好像有些问题,楼主自己调整吧
|
|