pano po lagyan ng space yung underscore yung code sa ibaba hindi po dapat mag gagawa ng linya?
import random
randomNum = random.randint(1,100)
attempts = 1
print("Welcome to the Number Guessing Game!")
print(f"I have chosen a random number between 1 and 100.\nTry to guess the number.")
while True:
guess = input("Enter your guess (or 'quit' to exit): ")
if guess.lower() == "quit":
print(f"The correct number was {randomNum}. Thanks for playing!")
break
if not guess.isdigit():
print("Enter a valid integer")
continue
guess = int(guess)
if randomNum == guess:
print(f"Congratulations! You guessed the number {randomNum} in {attempts} attempts.")
break
elif randomNum - guess <= 5 and randomNum - guess >= -5:
print("Getting hot.")
elif randomNum - guess <= 10 and randomNum - guess >= -10:
print("Getting warm.")
else:
print("You are not near the number")
attempts += 1
the result should be like in the picture
import random
randomNum = random.randint(1,100)
attempts = 1
print("Welcome to the Number Guessing Game!")
print(f"I have chosen a random number between 1 and 100.\nTry to guess the number.")
while True:
guess = input("Enter your guess (or 'quit' to exit): ")
if guess.lower() == "quit":
print(f"The correct number was {randomNum}. Thanks for playing!")
break
if not guess.isdigit():
print("Enter a valid integer")
continue
guess = int(guess)
if randomNum == guess:
print(f"Congratulations! You guessed the number {randomNum} in {attempts} attempts.")
break
elif randomNum - guess <= 5 and randomNum - guess >= -5:
print("Getting hot.")
elif randomNum - guess <= 10 and randomNum - guess >= -10:
print("Getting warm.")
else:
print("You are not near the number")
attempts += 1
the result should be like in the picture
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.