0

So - I'm new to Python and just messing around with some basic games to get my head around the language.. For whatever reason this little code returns "Invalid Syntax on Line 8" which is the "While guessedwrong == 1" line... Can anyone tell me why?

from random import randint

UserResponse = int(input("Guess what number between 1 and 100 I'm thinking 
of!"))
RandomNumber = randint(1,100)
guessedwrong = 1

While guessedwrong == 1:
    If UserResponse > RandomNumber:
        print("Nope! Lower!")
        UserResponse = int(input("Try again!"))
    elif UserResponse < RandomNumber:
        print("Njet! Higher!")
        UserResponse = int(input("Try again!"))
    else
        print("Correct! You're awesome!")
        GuessedWrong = 0
6
  • 2
    make all characters of if and while lowercase. Python is case-sensetive programming language. Commented Sep 13, 2017 at 12:00
  • if, while should be in lowercase. Commented Sep 13, 2017 at 12:01
  • guessedWrong = 0 Commented Sep 13, 2017 at 12:01
  • guessedwrong* Commented Sep 13, 2017 at 12:02
  • Also, third last line - Add colon after else Commented Sep 13, 2017 at 12:03

2 Answers 2

5

Python is case sensitive:

while guessedwrong == 1:
#^
    if UserResponse > RandomNumber
     #^

    # Some other your code
    else:
    #  ^^
        print("Correct! You're awesome!")
        guessedwrong = 0
        # ^^^^^^
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! Thought it was that easy!
Yeah, I figured that out just now on my own. Thanks!
0

Full corrected code

from random import randint

UserResponse = int(input("Guess what number between 1 and 100 I'm thinking of!"))
RandomNumber = randint(1, 100)
guessedwrong = 1

while guessedwrong == 1:
    if UserResponse > RandomNumber:
        print("Nope! Lower!")
        UserResponse = int(input("Try again!"))
    elif UserResponse < RandomNumber:
        print("Njet! Higher!")
        UserResponse = int(input("Try again!"))
    else:
        print("Correct! You're awesome!")
        guessedwrong = 0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.