samedi 20 avril 2019

How to overwrite a function within an if statement?

I'm new to Python and I was just experimenting with creating a simple calculator, and for some reason a function won't get overwritten. Whatever operator I input, the result will stay the same at 3125.

I tried using the percentage symbol but it is still stuck on one output.

num1 = float(input("First Number: "))
op = input("Operator: ")
num2 = float(input("Second Number: "))

if op == "^" or "**":
    result = float(num1) ** float(num2)
    print("Result: %s" % result)
elif op == "/"or "÷":
    result = float(num1) / float(num2)
    print("Result: %s" % result)
elif op == "x" or "*" or ".":
    result = float(num1) * float(num2)
    print("Result: %s" % result)
elif op == "+":
    result = float(num1) + float(num2)
    print("Result: %s" % result)
elif op == "-":
    result = float(num1) - float(num2)
    print("Result: %s" % result)

Why is it stuck, and why on 3125? This confuses me as I looked into other calculator codes and mine look the same.

Aucun commentaire:

Enregistrer un commentaire