Q:

Doing something doesn't work the first time, but the second time does work?

So I am making my simple calculator, any this is what I have so far:
import time
print ("Welcome. This is a calculator that uses the function: A (operator) B.")
time.sleep(3.5)
print ("Available operators include: Addition, Subtraction, Multiplication, Division,     Exponent, and Remainder division.")
time.sleep(3.5)
while True:
    a = float(input("Type in a value of A. "))
    b = float(input("Type in a value of B. "))
    opera = input("Would you like to: Add - Subtract - Multiply - Divide - Exponent - or Remainder? ")
    opera = opera.lower()
    while not (opera) == "add" or (opera) == "subtract" or (opera) == "multiply" or (opera) == "divide" or (opera) == "exponent" or (opera) == "remainder":
        print ("Invalid operation.")
        opera = input("Would you like to: Add - Subtract - Multiply - Divide - Exponent - or Remainder? ")
        break
    if (opera) == "add":
        print ((a) + (b))
    if (opera) == "subtract":
        print ((a) - (b))
    if (opera) == "multiply":
        print ((a) * (b))
    if (opera) == "divide":
        print ((a) / (b))
    if (opera) == "exponent":
        print ((a) ** (b))
    if (opera) == "remainder":
        print ((a) % (b))
    cont = input("Would you like to do another problem?")
    cont = cont.lower()
    if cont != "yes":
        break
    quit

So, when I start the calculator and put in values for a and b, putting anything except add will result in invalid operation. It will then prompt me to put a valid operation, and then it works for all of the operations. How can I fix that? I'm assuming the problem has to do with the while not inside the while true.

A:

I think it's a parenthetical issue. 
 while not (opera) == "add" or (opera) == "subtract" or (opera) == "multiply" or (opera) == "divide" or (opera) == "exponent" or (opera) == "remainder":

Should be
 while not ((opera) == "add" or (opera) == "subtract" or (opera) == "multiply" or (opera) == "divide" or (opera) == "exponent" or (opera) == "remainder"):

Your not is only applying to the first term, "add".
The reason it works after that is you never return to the while not conditional because of the break.
I'd look at dictionaries as a much more elegant way to solve this type of problem.

