だから私は簡単な電卓を作っています。これは私がこれまでに持っているものです:
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
そのため、電卓を起動して a と b の値を入力すると、add 以外の値を入力すると無効な操作になります。次に、有効な操作を入力するように求められ、すべての操作で機能します。どうすれば修正できますか?問題は、while true の内部ではなく while に関係していると思います。