计算器,使用python,0使用1st,它永远不会识别第二个输入来计算。

Calculator, using python, 0 used 1st, it never recognizes the second input to calculate.

print("1: ADDITION")
print("2: SUBTRACTION")
print("3: MULTIPLICATION")
print("4: DIVISION")

CHOICE = input("Enter the Numbers:")

if CHOICE == "1":
num1 =(input("Enter the value of num1:"))

    if num1=="0": #if 0 is used
    print ("Invalid Number")
    if num1 =="0": #if 0 is used
        input("Enter the value of num1:") #Enter number,0 used to get error
    if num1 !="0":
        print (num1)
    num2 =(input("Enter the value of num2:"))
    if num2=="0": #if 0 is used.
        print ("Invalid Number")
    if num2 =="0": #if 0 is used.
        input ("Enter the value of num2:") #Enter number,0 used to get error
    if num2 !="0":`enter code here`
        print (num2)
    value = float(num1) + float (num2) #this only solves for 1st input   
    print ("The sum of each num1 added to each num2:" + str(value))

我试图将其用作计算器,最初导致错误,然后在第二次尝试时输入正确的信息。这永远不会识别第二次尝试信息。它只获取 num1 和 num2 的第一个信息。我怎样才能识别第二个输入,即需要添加的数字?

更好的方法是使用while循环来收集输入,只有在收到有效数据后才退出while循环。

num1 = 0
while num1 == 0:
    value = input(....
    if ValidateInput(value):
        num1 = value
num2 = 0
while num2 == 0:
    value = input(....
    if ValidateInput(value):
        num2 = value
# do other stuff

def ValidateInput(input):
    """Common code that ensures the input is a numerical value, etc"""