|
发表于 2018-9-18 18:28:45
|
显示全部楼层
本帖最后由 pyhero 于 2018-9-18 18:56 编辑
- import random
- chances = int(input('Guess number game, how many chances do you want: '))
- guess = int(input('Guess the number(1-9, {} chances): '.format(chances)))
- dst = random.randint(1, 9)
- if guess not in range(1, 10):
- print('Bad input, chose from {}'.format([x for x in range(1, 10)]))
- else:
- chances -= 1
- while True:
- if guess > dst:
- guess = int(input('too big, guess again: '))
- elif guess < dst:
- guess = int(input('too small, guess again: '))
- if guess == dst:
- print('Good')
- break
- chances -= 1
- if chances <= 0:
- print('Game Over, my number is {}'.format(dst))
- break
复制代码 |
|