程序要求:猜一个随机的一到十的数字,三次机会,每次猜不中会提示大了或小了
以下是我编写的代码:
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)
想变简洁一点,求指导!!!