Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Can someone tell me what I'm doing wrong here, I keep getting line 10 'else' Syntax error

+3 votes
asked Sep 25, 2022 by Uzair (150 points)
import random

number = random.randrange(1,50)
guess = int(input("Guess a number between 1 and 50: "))

while guess != number:
    if guess < number:
        print("You need to guess higher. Try again.")
        guess = (int(input("\nGuess a number between 1 and 50: "))
    else:
        print ("You need to guess lower. Please try again")
        guess = (int(input("\nGuess a number between 1 and 50: "))
print("You guessed the number correctly!"

1 Answer

+1 vote
answered Sep 25, 2022 by xDELLx (10,500 points)

Good Code: guess = int(input("Guess a number between 1 and 50: ")) #Line#4

Bad Code:   guess = (int(input("\nGuess a number between 1 and 50: ")) #Line #9,12

Parenthesis are not aligned correctly on Bad code.

Either add ')' at end of lines 12,9 or use code from line 4

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...