|
| 1 | +num1=int(input("eneter a digit")) |
| 2 | +num2=int(input("eneter a another digit")) |
| 3 | +# defination for operators |
| 4 | + |
| 5 | +#addition |
| 6 | +def add(num1, num2): |
| 7 | + return num1+num2 |
| 8 | +#substraction |
| 9 | +def subtract(num1, num2): |
| 10 | + return num1-num2 |
| 11 | +#multiply |
| 12 | +def multiply(num1, num2): |
| 13 | + return num1*num2 |
| 14 | +#division |
| 15 | +def divide(num1, num2): |
| 16 | + return num1/num2 |
| 17 | + |
| 18 | +#command for operation |
| 19 | +print("choose operation") |
| 20 | +print("press 1 for add") |
| 21 | +print("press 2 for subs") |
| 22 | +print("press 3 for multiply") |
| 23 | +print("press 4 for devision") |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +while True: |
| 30 | + # take input from the user |
| 31 | + choice = input("Enter choice(1/2/3/4): ") |
| 32 | + |
| 33 | + if choice in ('1', '2', '3', '4'): |
| 34 | + |
| 35 | + if choice == '1': |
| 36 | + print(num1, "+", num2, "=", add(num1, num2)) |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + elif choice == '2': |
| 41 | + print(num1, "-", num2, "=", subtract(num1, num2)) |
| 42 | + |
| 43 | + elif choice == '3': |
| 44 | + print(num1, "*", num2, "=", multiply(num1, num2)) |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + elif choice == '4': |
| 51 | + print(num1, "/", num2, "=", divide(num1, num2)) |
| 52 | + # check if user wants another calculation |
| 53 | + # break the while loop if answer is no |
| 54 | + next_calculation = input("Let's do next calculation? (yes/no): ") |
| 55 | + if next_calculation == "no": |
| 56 | + break |
| 57 | + |
| 58 | + else: |
| 59 | + print("Invalid Input") |
0 commit comments