Python Forum

Full Version: Syntax error in if line
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello, I am very new to coding in general and python is my first. I am trying to figure out what is wrong with this, but I can't. I always get syntax error on line 2, but to my inexperienced eye it looks fine, please help. (Also, I am really just playing so the code is a bit silly)

lazy = int(raw_input("How lazy are you? (write number 1-100)")
if lazy < 20:
   print("Go RUN RUN RUN")
elif < 45:
   print("we can still go running, let's grab something and go")
elif < 70:
   print("okay, let's just go for a walk")
elif <= 100:
   print("Hm, let's just grab some nice coffee")
else:
   print("hey, that's too much lazy, you were supposed to be max lazy 100, you lazy girl!")
if lazy < 20:
               ^
SyntaxError: invalid syntax
lazy = int(raw_input("How lazy are you? (write number 1-100)")
The Syntax Error is in line 1. You should close parenthesis:

lazy = int(raw_input("How lazy are you? (write number 1-100): "))
If you start learning Python, you should avoid ancient version from the last century.
Use Python 3.6.
Thank you very much. As a matter of fact, I use Python 3.6.2. When I fixed the line 1 I got another error in line 4

lazy = int(input("How lazy are you? (write number 1-100) "))
if lazy < 20:
   print("Go RUN RUN RUN")
elif < 45:
   print("we can still go running, let's grab something and go")
elif < 70:
   print("okay, let's just go for a walk")
elif <= 100:
   print("Hm, let's just grab some nice coffee")
else:
   print("hey, that's too much lazy, you were supposed to be max lazy 100, you lazy girl!")
Error:
File "D:\Python\Inge.py", line 4    elif < 45:         ^ SyntaxError: invalid syntax
First you've used raw_input, which doesn't exist since Python 3. So this was a marker that you may be using Python 2.7.
All elif statements are wrong. You're comparing a number to what? A comparison operator needs always two operands.
Thank you. The thing is that I try to follow various tutorials and not all of them specify version of Python, I will do better.

As I understand using just IF would give me 3 outputs for the value 25, because it's less than 45, 70 and 100. I thought this can be avoided by using elif and you will get just one output for the value 25, which is the desired "we can still go running, let's grab something and go".

This is what I was trying to copy:
[Image: fRVHuk]
Did I understand everything wrong?

The code now works as I wanted it to. No idea how it happened.

lazy = int(input("How lazy are you? (write number 1-100) "))
if lazy < 20:
    print("Go RUN RUN RUN")
elif lazy < 45:
    print("we can still go running, let's grab something and go")
elif lazy < 70:
    print("okay, let's just go for a walk")
elif lazy <= 100:
    print("Hm, let's just grab some nice coffee")
else:
    print("hey, that's too much lazy, you were supposed to be max lazy 100, you lazy girl!")
Maybe you've used before just standalone if statements. Then every block is checking the condition for it's own.
If you're using if..elif..elif..elif..else there will be only executed one block.