+ 1
Hi guys been having problem with the if state code on pydroid app...
age =70 if age <=18 & age<=45 print("you are welcome to the party") elif age>45: print("you are very welcom") else: print("go home") print(20). THIS IS THE ERROR MESSAGE. Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module> start(fakepyfile,mainpyfile) File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(), __main__.__dict__) File "<string>", line 3 if age <=18 & age<=45 ^ SyntaxError: invalid syntax [Program finished]
2 Antworten
+ 1
In python we use keyword "and" exept &
if age <= 18 and age <= 45:
print("something")
You maybe make typo also, you check are age less or equal to 18 and check are age less or equal 45.
You probably mean greater than 18
age >=18 not age<=18
Also some indentation is wrong, i am not sure what print(20) do and this is also not indented well.
And you miss ":" after if statement
+ 1
Here is difference between "and" and "&"
https://www.geeksforgeeks.org/difference-between-and-and-in-JUMP_LINK__&&__python__&&__JUMP_LINK/amp/