I’m trying to do a simple calculator, but when I add the “if”, it is only making the first option, and not the “elifs”, when I ask to do them.
print("What are you going to do? (Multiplication(*), division(/), sum(+), subtraction(-), power (**) or root(R)?")
w = input(" ")
if w.upper() == "*" or "MULTIPLICATION" or "M":
fn = float(input("Enter the first number: "))
sn = float(input("Enter the second number: "))
print(fn * sn)
elif w.upper() == "/" or "DIVISION" or "D":
fn1 = float(input("Enter the first number: "))
sn1 = float(input("Enter the second number: "))
print(fn1 / sn1)
elif w.upper() == "+" or "SUM" or "S":
fn2 = float(input("Enter the first number: "))
sn2 = float(input("Enter the second number: "))
print(fn2 + sn2)
elif w.upper() == "-" or "SUBTRACTION" or "SU":
fn3 = float(input("Enter the first number: "))
sn3 = float(input("Enter the second number: "))
print(fn3 - sn3)
elif w.upper() == "**" or "POWER" or "P":
fn4 = float(input("Enter the first number: "))
sn4 = float(input("Enter the second number: "))
print(fn4 ** sn4)
elif w.upper() == "R" or "ROOT":
fn5 = float(input("Enter the number: "))
print(math.sqrt(fn5))
I was expecting to, when asked to do division, subtraction, sum and other, make it.
But, it is only making the first option, multiplication.
New contributor
Carone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.