设计了一个猜数字的程序,别人用了十几行,我这六十行了,有谁知道如何让这个代码更简洁,求大神指点!!!

程序要求:猜一个随机的一到十的数字,三次机会,每次猜不中会提示大了或小了

以下是我编写的代码:
import random
num = random.randint(1,10)
guess = int(input("请输入你猜测的数字(1~10):"))
if guess==num:
    print("你猜对了")
elif guess> num:
    print("你猜大了")
    guess = int(input("请输入你猜测的数字(1~10):"))
    if guess == num:
        print("你猜对了")
    elif guess > num:
        print("你猜大了")
        guess = int(input("请输入你猜测的数字(1~10):"))
        if guess == num:
            print("你猜对了")
        elif guess > num:
            print("你猜大了")
            print(num)
        elif guess < num:
            print("你猜小了")
            print(num)
    elif guess < num:
        print("你猜小了")
        guess = int(input("请输入你猜测的数字(1~10):"))
        if guess == num:
            print("你猜对了")
        elif guess > num:
            print("你猜大了")
            print(num)
        elif guess < num:
            print("你猜小了")
            print(num)
elif guess< num:
    print("你猜小了")
    guess = int(input("请输入你猜测的数字(1~10):"))
    if guess == num:
        print("你猜对了")
    elif guess > num:
        print("你猜大了")
        guess = int(input("请输入你猜测的数字(1~10):"))
        if guess == num:
            print("你猜对了")
        elif guess > num:
            print("你猜大了")
            print(num)
        elif guess < num:
            print("你猜小了")
            print(num)
    elif guess < num:
        print("你猜小了")
        guess = int(input("请输入你猜测的数字(1~10):"))
        if guess == num:
            print("你猜对了")
        elif guess > num:
            print("你猜大了")
            print(num)
        elif guess < num:
            print("你猜小了")
            print(num)

想变简洁一点,求指导!!!

你可能感兴趣的:(python,前端,开发语言)