r/CodingArea • • Jan 16 '21

Python Python basic calculator help

/r/CodingHelp/comments/kyg60m/python_basic_calculator_help/
1 Upvotes

1 comment sorted by

1

u/Zestyclose_Click_456 Apr 13 '21

This is a more simplified code that loops the question. Hope this helps!

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