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.
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:
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.
02-02-2024 10:36 AM
Has this been resolved?
03-04-2024 05:29 PM
It seems like you're encountering an issue with your code related to taking input from the user. Without seeing the actual code, I can provide you with a general example of how to take user input in Python. Make sure you're using the input() function to get user input.
Here's a simple example that you can adapt for your guessing game:
import random
def guess_the_number():
# Generate a random number between 1 and 100
secret_number = random.randint(1, 100)
while True:
try:
# Get user input
user_guess = int(input("Guess the number (between 1 and 100): "))
# Check if the guess is correct
if user_guess == secret_number:
print("Congratulations! You guessed the correct number.")
break
elif user_guess < secret_number:
print("Too low. Try again.")
else:
print("Too high. Try again.")
except ValueError:
print("Invalid input. Please enter a valid number.")
if __name__ == "__main__":
guess_the_number()
In this example, the program generates a random number between 1 and 100, and the user is prompted to guess the number. The program then provides feedback on whether the guess is too high, too low, or correct. If the user enters a non-numeric value, a ValueError exception is caught, and the user is prompted to enter a valid number.
If you're still having issues after adapting your code with this example, please share your code, and I'll do my best to assist you further.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide