invalid syntax

已回答

I have newly installed pycharm 2017.2.3.

i have tried to run this simple code:

x = [10]

if x > 5;

print(X)

but whenever i run the code it shows the following error

File "C:/Users/ACER/PycharmProjects/untitled1/name.py", line 2
if x>5
^
SyntaxError: invalid syntax

Process finished with exit code 1

please help me to solve it

0

Hi Siyam! There should be colon after if expression, print also should have 4 space indentation, like that:

x = [10]
if x > 5:
    print(x)
0
Avatar
Permanently deleted user

Thank you very much.

I always made the mistake of putting semicolon instead of colon

0
Num1 = int(input('What is your 1st Number'))

Num2 = int(input('What is your 2nd number'))

if Num1<Num2:
SENTENCE = Num2
SENTENCE1 = int("is greater number than")
SENTENCE3 = Num1
print(SENTENCE + SENTENCE1 + SENTENCE3 )

else: print(Num2 + int("is greater number than"))
WHAT IS WRONG IN HERE
0
Num1 = int(input('What is your 1st Number'))

Num2 = int(input('What is your 2nd number'))

if Num1<Num2:
SENTENCE = Num2
SENTENCE1 = int("is greater number than")
SENTENCE3 = Num1
print(SENTENCE + SENTENCE1 + SENTENCE3 )

else: print(Num2 + int("is greater number than"))
WHAT IS WRONG IN HERE
0

Try this:

def main():
num1 = input('What is your 1st Number: ')
num2 = input('What is your 2nd number: ')

s1 = str(num2)
s2 = "is greater number than"
s3 = str(num1)

if int(num1) < int(num2):
print(f'{s1} {s2} {s3}')
else:
print(f'{s3} {s2} {s1}')


if __name__ == '__main__':
main()
0

请先登录再写评论。