Function looping


#1

I need help in looping this to execute the function and be able to select another choice.
all i get is the function executing and repeating…
I need to execute the function and be able to select another choice.



   while (choice!="Q"):
    if choice=="A":
        num1=int(input("enter 1st number"))
        num2=int(input("enter 2nd number"))
        sum=addition(num1,num2)
        print(sum)
    if choice=="B":
        num1=int(input("enter your 1st number"))
        num2=int(input("enter your 2nd number"))
        difference=subtraction(num1,num2)
        print(difference)
    if choice=="C":
        num1=int(input("enter your 1st number"))
        num2=int(input("enter your 2nd number"))
        quotient=division(num1,num2)
        print(quotient)
    if choice=="D":
        num1=int(input("enter your 1st number"))
        num2=int(input("enter your 2nd number"))
        product=multiplication(num1,num2)
        print(product)
    if choice=="Q":
        print("quit")


#2

Since your choice is an input, you need to re-add that input after all the print statements you have except for the last one since that ends the loop.

eg.

while (choice!="Q"):
    if choice=="A":
        num1=int(input("enter 1st number"))
        num2=int(input("enter 2nd number"))
        sum=addition(num1,num2)
        print(sum)
        choice = input("Make another choice") #Do the same for the other choices except for choice == "Q"
...

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.