gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
Create a guessing game in python 3, where the player should try to guess a random number…
- User
Create a guessing game in python 3, where the player should try to guess a random number between 1 and 100 that can be played multiple times. After each run should the number of guesses be recorded so that a high score can be shown when finished playing
- Assistant
import random
def guessing_game(): # generate random number between 1 and 100 number = random.randint(1, 100)
# keep track of guesses and initialize to 0 num_guesses = 0 # initialize high score to a large number high_score = 1000 # loop until user correctly guesses the number while True: guess = input("Guess a number between 1 and 100: ") num_guesses += 1 # check if user input is valid if not guess.isdigit(): print("Invalid input") continue guess = int(guess) # check if guess is correct if guess == number: print("Correct! You guessed the number in", num_guesses, "guesses.") # update high score if num_guesses < high_score: high_score = num_guesses print("New high score!") else: print("High score:", high_score) play_again = input("Do you want to play again? (y/n)") # check if user wants to play again if play_again == "y": guessing_game() else: print("Thanks for playing!") break # check if guess is too high or too low elif guess < number: print("Too low! Guess again.") else: print("Too high! Guess again.")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.