mardi 13 juillet 2021

if statement problem, Outputs all if statements at the same time [duplicate]

I started learning python literally yesterday and decided to write somewhat of a simple calculator. My problem is that my code outputs all of my if statements rather than just one of them... I tried searching up the problem and found of using the elif statement so when I tried it would only output my first if statement. This is my code so far:

Number2 = float(input("Second Number:"))
Type = str(input("What Type Of Math:"))
if Type == "Addition" or "addition" or "add" or "Add" or "+":
    Adition = Number1 + Number2
    print("When Added You Get:" + str(Adition))
    
elif Type == "Multiply" or "x" or "multiply" or "multiplication" or "Multiplication":
    Mult = Number1 * Number2
    print("When Multiplied You Get:" + str(Mult))
    
elif Type == "Sub" or "-" or "sub" or "Subtract" or "subtract":
    Sub = Number1 - Number2
    print("When Subtracted You Get:" + str(Sub))
    
elif Type == "Divide" or "divide" or "/" or "div" or "Div":
    DIV = Number1 / Number2
    print("When Divided You Get:" + str(DIV))

The code above always just outputs the addition equation...

I would like to keep it inside this format if possible but any answers would be deeply appreciated! Thanks!

Aucun commentaire:

Enregistrer un commentaire