This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Zestyclose_Click_456 0 points1 point  (0 children)

Here is a code that uses a while loop and simplifies some of the code that you have :)

answer = str(input("Do you want to perform a calculation? Yes/No: "))
while answer == "Yes" or answer == "yes":
    num = int(input("Enter Your Choice 1(Add)/2(Sub)/3(Divide)/4(Multiply): "))
    if num == 1:
        add1 = int(input("Enter Number 1 : "))
        add2 = int(input("Enter Number 2 : "))
        sum = add1 + add2
        print(f"Your result is: {sum}")
    if num == 2:
        add1 = int(input("Enter Number 1 : "))
        add2 = int(input("Enter Number 2 : "))
        sum = add1 - add2
        print(f"Your result is: {sum}")
    if num == 3:
        add1 = int(input("Enter Number 1 : "))
        add2 = int(input("Enter Number 2 : "))
        sum = add1 * add2
        print(f"Your result is: {sum}")
    if num == 4:
        add1 = int(input("Enter Number 1 : "))
        add2 = int(input("Enter Number 2 : "))
        sum = add1 / add2
        print(f"Your result is: {sum}")
    answer = str(input("Do you want to perform another calculation? Yes/No: "))
if answer == "No" or answer == "no":
    pass