0
Invalid syntax
x = input if x = 3 print("It is three") Showing an error on line 2, explain someone please what is wrong?
3 Respuestas
+ 1
If I want to do it in C++, I'll write it this way:
int input = (something);
int x = input;
if (x == 3) {
cout << "It is three";
}
For the error, I assume it is because you don't have any ( ) around x = 3. Also x =3 is wrong, it must be x == 3 because you are not giving x value, instead you are comparing its value.
+ 1
x=input () #you missed ()
if x==3: #you missed == and :
print ("it is three")
0
It's because you are using 1 equal instead of 2.
when you write this
a = 5
You are using the assignment operator, which stores the number 5 on the variable a.
When you write this
a==5
You are comparing the value stored in variable a with the number 5, checking for equality. This is the equals operator, and returns a boolean.
You get a syntax error because you are not comparing, instead, you are assigning a variable.