import random
def start_game():
print("\nWelcome to the Number Guess game!")
print("Guess a number between 1 and 100\n")
number = random.randint(1, 100)
guess = None
attempts = 0
while guess != number:
guess = int(input("Enter your guess: "))
attempts += 1
if guess > number:
print("Too high! Try again.")
elif guess < number:
print("Too low! Try again.")
else:
print("\nCongratulations! You guessed the number in", attempts, "attempts.")
play_again = input("\nDo you want to play again (yes/no): ")
if play_again.lower() == "yes":
start_game()
else:
print("\nThanks for playing! See you next time.")
if __name__ == "__main__":
start_game()
用python写一个猜数字游戏
最新推荐文章于 2023-03-12 22:49:27 发布