Grok Number guessing game - learn python

//import random //# Generate a random number between 1 and 10 //number_to_guess = random.randint(1, 10) //# Initialize the number of guesses //guesses = 0 //# Main game loop //while True: // # Ask the player for their guess // guess = int(input("Guess a number between 1 and 10: ")) // guesses += 1 // # Check if the guess is correct // if guess < number_to_guess: // print("Too low! Try again.") // elif guess > number_to_guess: // print("Too high! Try again.") // else: // print(f"Correct! You guessed it in {guesses} tries.") // break This script does the following: Imports random for generating random numbers. Generates a random number that the player needs to guess. Uses a while loop to keep the game going until the correct number is guessed. Takes input from the player, converting it to an integer since input() returns a string. Compares the guess with the number to guess, giving feedback. Breaks the loop when the guess is correct, ending the game. To make this into a Windows executable: Install PyInstaller if you haven't already: Open Command Prompt or PowerShell. Run pip install pyinstaller. Navigate to your script's directory in the command line. Use PyInstaller to create the executable: Run pyinstaller --onefile your_script_name.py. Replace your_script_name.py with the name of your Python file. This will create an executable in a dist folder within your project directory. You can then distribute this .exe file, which will run on Windows without needing Python installed. This simple game will help you understand basic Python syntax, loops, conditionals, and user input. Once you're comfortable with this, you can expand it or move on to more complex projects.

Comments