+ 1
why conditional "if" is looping for first and second line even it is false
# calculator calculate = input("Which operation you want to do? Press '+' for addition, '-' for substaction, '*' for multiplication and '/' for division: ") if calculate == "+" or "-" or "*" or "/": a=float(input("First number: ")) b=float(input("Second number: ")) if calculate == "+": print(a+b) elif calculate == "-": print(a-b) elif calculate == "*": print(a*b) else: print(a/b) else: print("Invalid Operator")
3 ответов
+ 10
The if statement should be:
if calculate == "+" or calculate == "-" or calculate == "*" or calculate == "/":
but you better use:
if calculate in ['+','-','*','/']:
+ 2
This is the Boolean logic
On the first line: "+" or "-" or "*" or "/" always evaluates to True,
You don't want that, you want:
something == another or something == something else
+ 1
Ali Abdelhady Lothar thank you bros...it really help me. 😊