python----猜数字游戏

版权声明:https://blog.csdn.net/weixin_42499593 https://blog.csdn.net/weixin_42499593/article/details/89196494

题目要求:
猜数字游戏

  1. 系统随机生成一个1~100的数字;
  2. 用户总共有5次猜数字的机会;
  3. 如果用户猜测的数字大于系统给出的数字,打印“too big”;
  4. 如果用户猜测的数字小于系统给出的数字,打印"too small";
  5. 如果用户猜测的数字等于系统给出的数字,打印"恭喜",并且退出循环;
import random

trycount = 0
computer = random.randint(1,100)
print(computer)
while trycount < 5:
    player = int(input('Num:'))
    if player > computer:
        print('too big')
        trycount += 1
    elif player < computer:
        print('too small')
        trycount += 1
    else:
        print('恭喜')
        break

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42499593/article/details/89196494