python not recognizing '+'

Viewed 29

I have an if statement checking to see if a variable from my list is equal to '+' and when it is, it just skips over it and does nothing, view lines down it also has an if statement checking to see if the same variable from the same list is equal to 'X' or 'x' or '*' and for some weird reason it says it is. I got it to print the variable right after it checks and it was still a + when it said it was equal to 'X' or 'x' or '*'. please help.

code:

import time
while 1 == 1 :
  operation = 0
  fff = input()
  fff = fff.split()
  VarNum = len(fff)
  if VarNum >= 1 :
    Num1 = fff[0]
    Num1 = int(Num1)
  if VarNum >= 3 :
    Num2 = fff[2]
    Num2 = int(Num2)
  if VarNum >= 2 :
    if (fff[1]) == '+' :
      operation = 1 
    if (fff[1]) == '-' :
      operation = 2 
    if (fff[1]) == 'X' or 'x' or '*' :
      operation = 3
    if (fff[1]) == '/' :
      operation = 4 
    if operation == 1 :
      answer = Num1 + Num2
    if operation == 2 :
      answer = Num1 - Num2
    if operation == 3 :
      print(Num1)
      print(Num2)
      print(operation)
      print(fff[1])
      answer = Num1 * Num2
    if operation == 4 :
      answer = Num1 / Num2
    answer = str(answer)
    print("Your answer is " + answer)
0 Answers
Related