import random

'''
实现一个猜数字小游戏,随机生成一个0~100以内的数据,由玩家来猜
每次猜完之后计算机告诉玩家是猜大了还是猜小了
共5次机会,5次猜不出来宣布游戏失败。

'''


class GuessNum:

    def Num(self):
        random.seed()
        self.num = random.randint(1, 100)
        return self.num

    def Guess(self):
        num = self.Num()
        for b in range(5, 0, -1):
            gussnum = int(input('请输入你猜的数值: '))
            if gussnum > num:
                print('您猜的值偏大')
            elif gussnum < num:
                print('您猜的值偏小 ')
            else:
                print('猜对了')
                break
        else:
            print('很遗憾,挑战失败,所猜值为%d' % num)


def main():
    a = GuessNum()
    a.Guess()
    while True:
        print()
        d = input('是否继续挑战(Y/N)?')
        if d in ('Y', 'y'):
            a = GuessNum()
            a.Guess()
        elif d in ('N', 'n'):
            break
        else:
            print("输入错误请重新输入")
            continue



if __name__ == '__main__':
    main()




import random

for i in range(1, 6):

    a = random.randint(0, 100)
    b = int(input("请输入你所猜的数字:"))
    if a == b:
        print("恭喜你猜对了!!!")
        break
    elif a < b:
        print("你猜大了!!!,正确数字是:%d" % a)
        continue
    else:
        print("你猜小了!!!,正确数字是:%d" % a)
        continue
else:
    print("你失败了!!!")





import random
s = random.randint(0,100)
i = 0
while i<5:
    player = int(input())
    if player == s:
        print('胜利')
        break
    elif player < s:
        print(f'小了,你还有{4-i}次机会')
        i += 1
    elif player >s:
        print(f'大了,你还有{4-i}次机会')
        i +=1
print('游戏结束')





import random

start = random.randint(0, 100)
i = 1
while i < 6:
    gust = int(input('第 %d 次机会:' % i))
    if i == 5 and start != gust:
        print('5次都错了,游戏结束,数字是: %d' % start)
        break
    elif start == gust:
        print('你猜对了,数字是: %d' % start)
        break
    elif start > gust:
        print('数小了')
        i = i + 1
        continue
    elif start < gust:
        print('数大了')
        i = i + 1
        continue