o1-preview-2024-09-12· OpenAI
WildChat-4.8M (AI2)
Write a game
- User
Write a game
- Assistant
Certainly! Here's a simple number guessing game written in Python:
python
Write a game
Certainly! Here's a simple number guessing game written in Python:
import random
def guess_the_number():
number_to_guess = random.randint(1, 100)
attempts_remaining = 10
print("Welcome to 'Guess the Number'!")
print("I'm thinking of a number between 1 and 100.")
print("You have 10 attempts to guess it.\n")
while attempts_remaining > 0:
try:
guess = int(input("Enter your guess: "))
attempts_remaining -= 1
if guess < number_to_guess:
print("Too low!")
elif guess > number_to_guess:
print("Too high!")
else:
print(f"🎉 Congratulations! You guessed the number {number_to_guess}!")
break
if attempts_remaining > 0:
print(f"You have {attempts_remaining} attempts remaining.\n")
else:
print(f"😞 Sorry, you've run out of attempts. The number was {number_to_guess}.")
except ValueError:
print("🚫 Please enter a valid integer.\n")
if __name__ == "__main__":
guess_the_number()
This is a simple number guessing game where:
To play the game:
guess_the_number.py.python guess_the_number.py
Enjoy the game! If you'd like to explore more features or different games, feel free to ask.
Not yet included in a published release.