Python Forum
invalid syntax in line 5. Help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: invalid syntax in line 5. Help (/thread-31429.html)



invalid syntax in line 5. Help - Asadzangibaloch - Dec-10-2020

if string 1 length is greater than print true else false. but there is a problem can u please help me

invalid syntax in line 5

1- string1=input("Enter a word: ")
2- string2=input("Please enter another word: ")
3- if len(string1) > len(string2):
4- print("True")
5- else:
6- print("false")


RE: invalid syntax in line 5. Help - DPaul - Dec-10-2020

If you were to indent lines 4 and 6, the syntax would be ok.
Paul


RE: invalid syntax in line 5. Help - deanhystad - Dec-10-2020

Please wrap code in Python tags (see the Python button in the editor).

Most likely you have an indentation error. This code runs:
string1=input("Enter a word: ")
string2=input("Please enter another word: ")

if len(string1) > len(string2):
    print("True")
else:
    print("false")

print("True" if len(string1) > len(string2) else "false")
You can also use a ternary expression like that in the bottom line.