gpt-4-0314· openai
Suzhen/CodeChat
Program the following in simple functional Python code: Implement the guessing game with…
- User
Program the following in simple functional Python code: Implement the guessing game with a menu system. The resting of the magic number should not be acknowledged, but not displayed. The user has to guess a number between 1-10. Have the Play make a single guess with "low" or "high" or "correct" messaging. After a guess, go back to the main menu.
Guessing game
- Reset magic number
- Play
- Quit Enter choice:
Example output: Guessing game
- Reset magic number
- Play
- Quit Enter choice: 1 Magic number reset
Guessing game
- Reset magic number
- Play
- Quit Enter choice: 2 Enter guess (1-10): 4 low
Guessing game
- Reset magic number
- Play
- Quit Enter choice: 3 bye
- Assistant
import random def main_menu(): print("Guessing game") print("1. Reset magic number") print("2. Play") print("3. Quit") choice = int(input("Enter choice: ")) return choice def reset_magic_number(): magic_number = random.randint(1, 10) print("Magic number reset") return magic_number def play(magic_number): guess = int(input("Enter guess (1-10): ")) if guess == magic_number: print("correct") elif guess < magic_number: print("low") else: print("high") def main(): magic_number = random.randint(1, 10) while True: choice = main_menu() if choice == 1: magic_number = reset_magic_number() elif choice == 2: play(magic_number) elif choice == 3: print("bye") break else: print("Invalid choice") if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.