cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1778
Views
0
Helpful
2
Replies

2.1.3.8 Lab - create a simple game with python IDLE

Khadkay
Level 1
Level 1

Hello,

Having written the code as I saw it and corrected evident errors while trying to run the code in python IDLE, i do not know why i am unable to type/insert a number do the program can continue running.

Task is to create a game where the program guesses the number the player chooses.

assistance please.vb.png

2 Replies 2

It seems like you're working on a number guessing game where the program guesses the number chosen by the player. To help you further, I'd need to see the code you've written so far. However, I can provide you with a simple outline of how you can implement such a game in Python:

  1. Import the random module to generate random numbers.
  2. Define the minimum (min_number) and maximum (max_number) values for the range of numbers the player can guess.
  3. Generate a random target number within the specified range using random.randint.
  4. Initialize variables for tracking the number of guesses (guesses) and whether the guess is correct (is_guess_correct).
  5. Print a welcome message and instructions to the player.
  6. Enter a while loop that continues until the player's guess is correct.
  7. Inside the loop:
    • Attempt to get the player's guess as an integer using input and int.
    • Increment the number of guesses.
    • Check if the guess is correct, too low, or too high and provide appropriate feedback to the player.
    • Handle invalid input with a try and except block, informing the player to enter a valid number.
  8. Once the player guesses the correct number, exit the loop and print a congratulatory message with the target number and the number of guesses it took.

You can take this breakdown and write the code in your Python environment. If you encounter any specific issues while implementing it, feel free to ask for help with those particular problems.

This code sets up a simple number guessing game where the player needs to guess the randomly generated target number within a specified range. It uses a while loop to continue taking guesses until the player guesses correctly.

Ruben Cocheno
Spotlight
Spotlight

@Khadkay 

Has this been resolved?

Tag me to follow up.
Please mark it as Helpful and/or Solution Accepted if that is the case. Thanks for making Engineering easy again.
Connect with me for more on Linkedin https://www.linkedin.com/in/rubencocheno/