noahshine15
New Coder
I'm excited to share with you a small Python program I've been working on, although it does currently have some errors. I decided to use an online Python editor to thoroughly examine and debug the code. You can access this convenient online editor by clicking on the following link: Python Online Editor.
website link:
Python Online Editor and Compiler
Here's the code:
website link:
Python Online Editor and Compiler
Here's the code:
Python:
import random
secret_number = random.randint(1, 100)
attempts = 0
print("Welcome to the Guessing Game!")
print("I have selected a random number between 1 and 100.")
print("Try to guess the number.")
while True:
guess = random.randint(1, 100)
attempts + = 1
if guess < secret_number:
print(f"Attempt {attempts}: Guessed {guess}. It's too low. Try a higher number.")
elif guess > secret_number:
print(f"Attempt {attempts}: Guessed {guess}. It's too high. Try a lower number.")
else:
print(f"Congratulations! You've guessed the secret number {secret_number} in {attempts} attempts.")
break
print("Thank you for playing!")