I am trying to make a calculator and trying to have it loop. I made a new file to test it, when I run it instead of starting at while numvars =="1"
it is starting at e = int(input("What exponent do you want")
. This is even happening if you say no for the exponent. What exactly is the problem that is occurring?
from math import sqrt
numvars = input("how many numbers do you want? Please only pick a number 1-3. Only type out the numberical character")
switch = True
for x in numvars:
while numvars == "1":
if switch == True:
a = int(input("What number would you like? Type ONLY the numberical character and not the word"))
exponents = input("Want to use exponents? MUST BE written as 'yes' or 'no'")
if exponents == "yes" or "Yes" or "YES" or "Y":
root = input("Would you like to do a square root? yes or no")
if root == "yes" or "Yes" or "YES" or "Y":
e = int(input("What exponent do you want?"))
b = a ** e
c = sqrt(b)
print(a, "was put to the power of", e, "giving the result", b)
print(b, "was then square rooted giving", c)
if root == "no" or "No" or "NO":
e = int(input("What exponent do you want?"))
b = a ** e
print(a, "was put to the power of", e)
print("Giving the final answer of", b)
root = input("Would you like to do a square root? yes or no")
if exponents == "no" or "No" or "NO" or "N":
root = input("Would you like to do a square root? yes or no")
if root == "yes" or "Yes" or "YES" or "N":
b = sqrt(a)
print(a, "was square rooted giving the answer of", b)
This issue is also happening if I have it as if numvars == "1"
. else
also hasn't been working for me (using VisualStudio Code). Where I am wanting it to go back to is numvars = input("how many numbers do you want? Please only pick a number 1-3. Only type out the numberical character")
; only reason that for x in numvars:
being after the intended restart is just so I don't get an error of numvars
not being properly defined (unless I have loops misunderstood, which is possible).