import random
def guess_number_game():
number_to_guess = random.randint(1, 100)
attempts = 0
print("欢迎来到猜数字游戏!我想了一个1到100之间的数,你有5次机会猜出它.")
while True:
user_guess = int(input("请输入你的猜测: "))
attempts += 1
if user_guess < number_to_guess:
print("太小了,再试一次!")
elif user_guess > number_to_guess:
print("太大了,再试试!")
else:
print(f"恭喜你,猜对了!你用了{attempts}次尝试.")
break
guess_number_game()