-2

so I was trying to make a simple python calculator as I started learning the language lately and I tried to add to the power of function but whenever I debug the code it acts as if I typed * and not ^ so it does multipling instead of power for some reason can anyone help me please here is my code

from math import *
import time
delaytime=0.5
print("This is my python calculator!!")
time.sleep(delaytime)
num1=input("Please enter your first number: ")
time.sleep(delaytime)
op=input("Please enter your operator: ")
time.sleep(delaytime)
num2=input("Please enter your second number: ")
time.sleep(delaytime)
print("so your problem looks something like this ,(", num1, op, num2 , ")")
time.sleep(delaytime)
check=input("Am I right sir?")
lowercheck=check.lower()
if lowercheck == "yes" or "yup" :
    time.sleep(delaytime)
    print("Perfect")
    if op == "+":
        result=float(num1) + float(num2)
        time.sleep(delaytime)
        print("the result is ",result)
    elif op == "-":    
        result=float(num1) - float(num2)
        time.sleep(delaytime)
        print("the result is ",result)
    elif op == "x" or "X" or "*":    
        result=float(num1) * float(num2)
        time.sleep(delaytime)
        print("the result is ",result)
    elif op == "/" or "÷":    
        result=float(num1) / float(num2)
        time.sleep(delaytime)
        print("the result is ",result)
    elif op == "^" :
        result=pow(float(num1),float(num2))
        print(result)
elif lowercheck == "no" :
    print("Then please restart the program and try again")    

I don't really know what the problem is but I hope someone can help me sorry if it's a mess I'm kind of new to this

hustarico
  • 1
  • 1
  • 7
    That's not how you compare a single variable to multiple values. – Scott Hunter Mar 02 '22 at 16:55
  • 6
    Does this answer your question? [How to test multiple variables for equality against a single value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-for-equality-against-a-single-value) (Yes, the question is "multiple" but the answer still lies therein, and importantly explains _why_ this is the behaviour.) – msanford Mar 02 '22 at 16:55
  • `elif op == "x" or "X" or "*"` this is wrong. You're checking "`op` is equal to `"x"` OR `"X"` has length greater than 0 OR `"*"` has length greater than 0". You want to make the first comparison multiple times. – aaossa Mar 02 '22 at 16:56

1 Answers1

-1

One of the if conditions are incorrect:

# instead of
elif op == "/" or "÷": 

# write
elif op == "/" or op == "÷":
Florin C.
  • 593
  • 4
  • 13