|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
改进小游戏,提醒用户输入错误格式
- import random
- times = 3
- secret = random.randint(1,10)
- print('Welcome!!!!!!')
- guess = 0
- print("Guess what number do I think?", end = " ")
- while (guess != secret) and (times > 0):
- guess = int(input())
- while type(guess) != type(1):#应该是这里出问题了
- print("Illegal type!")
- times = times - 1
- if guess == secret:
- print("Bingo!")
- print("Huh, without prize!")
- else:
- if guess > secret:
- print("Too big!")
- else:
- print("Too small!")
- if times > 0:
- print("Try again!")
- else:
- print("You are out of chance!")
- print("Game over!")
复制代码
这样试试:
- import random
- times = 3
- secret = random.randint(1, 10)
- print('Welcome!!!!!!')
- guess = 0
- print("Guess what number do I think?", end=" ")
- while (guess != secret) and (times > 0):
- guess = input()
- while not guess.isdigit():
- guess = input("Illegal type! Please input: ")
- guess = int(guess)
- times = times - 1
- if guess == secret:
- print("Bingo!")
- print("Huh, without prize!")
- else:
- if guess > secret:
- print("Too big!")
- else:
- print("Too small!")
- if times > 0:
- print("Try again!")
- else:
- print("You are out of chance!")
- print("Game over!")
复制代码
|
|