2.1.3.8 Lab - create a simple game with python IDLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2020 07:38 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 10:48 AM - edited 10-03-2023 10:49 AM
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:
- Import the random module to generate random numbers.
- Define the minimum (min_number) and maximum (max_number) values for the range of numbers the player can guess.
- Generate a random target number within the specified range using random.randint.
- Initialize variables for tracking the number of guesses (guesses) and whether the guess is correct (is_guess_correct).
- Print a welcome message and instructions to the player.
- Enter a while loop that continues until the player's guess is correct.
- 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.
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 10:36 AM
Has this been resolved?
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/
