-1
input("Welcome to this calculator, press ENTER to continue")

operation = input("Type one : Add  Subtract  Multiply  Divide   ");
firstNumber = input("Type the first number you want to " + operation + "   ");
secondNumber = input("Type the second number   ");

if operation == "add" or "Add":
    finalNumber = int(firstNumber) + int(secondNumber); finalNumberString = str(finalNumber); newOperation = "adding "
elif operation == "multiply" or "Muptiply":
    finalNumber = int(firstNumber) * int(secondNumber); finalNumberString = str(finalNumber); newOperation = "multiplying "
else:
    print("Not Yet Implemented")

print("Your result of " + newOperation + firstNumber + " to " + secondNumber + " was " + finalNumberString)

When I run the script and try to multiply, it ends up adding them and prints "adding" instead of "multiplying"

Welcome to this calculator, press ENTER to continue
Type one : Add  Subtract  Multiply  Divide   Multiply
Type the first number you want to Multiply   10 
Type the second number   5
Your result of adding 10 to 5 was 15
  • 1
    For one; you misspelled "Multiply" in your second case `elif operation == "multiply" or "Muptiply":` – chrisbyte Aug 31 '22 at 18:14
  • 1
    It's because `and` and `or` don't work that way. Your expression is read `(operation == "add") or "Add"`, and since the string "Add" is always true, the if will always be taken. Use `if operation.lower() == "add":`. – Tim Roberts Aug 31 '22 at 18:15
  • 1
    `if operation == "add" or "Add":` is not the same as `if operation == "add" or operation == "Add":` - you probably want the later – Todd R Aug 31 '22 at 18:16
  • https://stackoverflow.com/questions/20002503/why-does-a-x-or-y-or-z-always-evaluate-to-true-how-can-i-compare-a-to-al this link fixed it – Crossbow4000 Aug 31 '22 at 18:17

1 Answers1

0

It works when I change

if operation == "add" or "Add":    and    elif operation == "multiply" or "Muptiply":

to

if operation == "add" or operation == "Add":    and   elif operation == "multiply" or operation == "Multiply":
  • Since this is the solution given in the proposed duplicate, there's no need to add a separate answer here. The way Stack Overflow works, we try to select a single canonical instance of each question, answer it as thoroughly as possible, and then direct other people with the same question there -- that way the effort of building the best possible answers (and vetting/improving/editing those answers) gets concentrated rather than spread out. – Charles Duffy Aug 31 '22 at 18:23