本帖最后由 Yydanchun 于 23-11-14 03:01 编辑
- print('----欢迎挑战数数游戏----')
- print(' 十次之内猜中算成功 ')
- print(' 输入101结束游戏 ')
- import random
- import time
- num = random.randint(1,100)
- a = 1
- c = 1
- d = 100
- while True:
- b = int(input(f"请输入{c}-{d}之间的整数:"))
- if b < num:
- print(f'猜小了')
- c = b
- elif b > num:
- print(f'猜大了')
- d = b
- elif b == 101:
- print('挑战失败,你已主动放弃')
- print(f'当前答案为:{num}')
- break
- elif b == num:
- print('恭喜你,答对了~!')
- print(f'您一共耗费了{a}次机会')
- time.sleep(3)
- if a <= 10:
- print('恭喜你挑战成功')
- break
- elif a > 10:
- print('很遗憾,挑战失败')
- break
- a += 1
复制代码
|
|