gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
code me a simple game
- User
code me a simple game
- Assistant
Sure! Here's an example of a simple number guessing game in Python:
import random def guess_number(): number = random.randint(1, 100) attempts = 0 while True: guess = int(input("Guess a number between 1 and 100: ")) attempts += 1 if guess == number: print(f"Congratulations! You found the number in {attempts} attempts.") break elif guess < number: print("Too low. Try again.") else: print("Too high. Try again.") # play the game guess_number()This code generates a random number between 1 and 100, and then prompts the player to enter their guess. It provides feedback on whether the guess is too low or too high and continues until the player guesses correctly. The number of attempts is also tracked and displayed at the end of the game when the correct number is guessed.