Python Forum

Full Version: invalid syntax in line 5. Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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")
If you were to indent lines 4 and 6, the syntax would be ok.
Paul
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.