我可以为您提供一个简单的小游戏。以下是一个猜数字的游戏:
规则:
- 系统会随机生成一个0到100之间的整数作为答案。
- 您需要在10次机会内猜出这个数字。
- 您每次猜测后,系统会告诉您是高了、低了还是猜对了。
准备好了吗?让我们开始!
import random
def guess_number():
answer = random.randint(0, 100)
attempts = 10
while attempts > 0:
print(f"You have {attempts} attempts left.")
guess = int(input("Enter your guess (0-100): "))
if guess < answer:
print("Too low!")
elif guess > answer:
print("Too high!")
else:
print("Congratulations! You guessed it right!")
break
attempts -= 1
if attempts == 0:
print(f"Game over! The answer was {answer}.")
guess_number()