+ 8
Why this code is not valid? Please explain me
4 Respuestas
+ 3
This is because you are using one(=) after if statement but there should be two(==)
one(=) equal sign is used to assign the value in a variable in python and to chech if it is equal or not we have to use two(==) equal signs otherwise it will throw an error
+ 2
Copy paste this and compare it with your piece of code.
num1 = int(input("Enter the first number:"))
op = input("Enter the operation:")
num2 = int(input("Enter the second number:"))
if op == "+" :
sum = num1 + num2
print("summation:", sum)
elif op == "-" :
sub = num1 - num2
print("subtraction:", sub)
elif op == "*" :
mul = num1 * num2
print("multiplication:", mul)
elif op == "/" :
div = num1 / num2
print("division:", div)
else:
print(" The operator is not valid ")
+ 1
Because the numbers are string
U should use int
int(input("enter "))
0
oops, youre using a bad character to end your if statements