I'm making a calculator program, it has a square root feature, but first, you need to type 's' in order to access it, I wanna make it so that the user can type "S" or "s" and have the computer still recognize it and bring up the square root option but if I add the s.upper() and the s variable it works but not as intended the code is:
import math
def calculator():
while True:
s = "s"
intro = input('Hello! Please type * for multiplication, / for division, + for addition, - for subtraction, ** for exponents, and "s" for square root \n')
if intro not in ["*", "/", "+", "-", "**", s.upper(), s]:
print ("that wasnt an option!")
continue
if intro != s:
num1 = int(input("Whats your first number \n"))
num2 = int(input("Whats your second number \n"))
if intro != s.upper():
num1 = int(input("Whats your first number \n"))
num2 = int(input("Whats your second number \n"))
if intro == "*":
print(num1 * num2)
break
elif intro == "/":
print(num1/num2)
break
elif intro == "+":
print(num1 + num2)
break
elif intro == "-":
print(num1 - num2)
break
elif intro == "**":
print(num1 ** num2)
break
elif intro == s.upper():
num_sqr = int(input("What number do you wanna find the square root of \n"))
print(math.sqrt(num_sqr))
break
elif intro == s:
num_sqr = int(input("What number do you wanna find the square root of \n"))
print(math.sqrt(num_sqr))
break
calculator()
whenever a user types s it ignores variables num1 and num2 so it can just do run the num_sqr variable so the output is:
s (or S)
Whats your first number
2
Whats your second number
4
What number do you wanna find the square root of
24
4.898979485566356
Rather than:
s (or S)
What number do you wanna find the square root of
24
4.898979485566356
Why is it doing this and how can I fix it?