|
1 |
| -while True: |
2 |
| - # definition for operators |
3 |
| - |
4 |
| - #addition |
5 |
| - def add(num1, num2): |
6 |
| - return num1+num2 |
7 |
| - |
8 |
| - #substraction |
9 |
| - def subtract(num1, num2): |
10 |
| - return num1-num2 |
11 |
| - |
12 |
| - #multiplication |
13 |
| - def multiply(num1, num2): |
14 |
| - return num1*num2 |
15 |
| - |
16 |
| - #division |
17 |
| - def divide(num1, num2): |
18 |
| - try: |
19 |
| - return num1/num2 |
20 |
| - except ZeroDivisionError: |
21 |
| - print ("WARNING: Invalid division, cannot divide by zero") |
22 |
| - |
23 |
| - #exponent |
24 |
| - def exponent(num1, num2): |
25 |
| - return num1**num2 |
26 |
| - |
27 |
| - while True: |
28 |
| - try: |
29 |
| - num1=float(input("Enter a digit: ")) |
30 |
| - num2=float(input("Enter another digit: ")) |
31 |
| - break |
32 |
| - except ValueError: |
33 |
| - print("The input was not a valid digit") |
| 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") |
34 | 24 |
|
35 |
| - #command for operation |
36 |
| - print("Choose an operation") |
37 |
| - print("Press 1 for addition") |
38 |
| - print("Press 2 for substraction") |
39 |
| - print("Press 3 for multiplication") |
40 |
| - print("Press 4 for division") |
41 |
| - print("Press 5 for exponent") |
42 | 25 |
|
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +while True: |
43 | 30 | # take input from the user
|
44 |
| - choice = input("Enter choice(1/2/3/4/5): ") |
| 31 | + choice = input("Enter choice(1/2/3/4): ") |
45 | 32 |
|
46 |
| - if choice in ('1', '2', '3', '4', '5'): |
| 33 | + if choice in ('1', '2', '3', '4'): |
47 | 34 |
|
48 | 35 | if choice == '1':
|
49 | 36 | print(num1, "+", num2, "=", add(num1, num2))
|
50 | 37 |
|
| 38 | + |
| 39 | + |
51 | 40 | elif choice == '2':
|
52 | 41 | print(num1, "-", num2, "=", subtract(num1, num2))
|
53 | 42 |
|
54 | 43 | elif choice == '3':
|
55 | 44 | print(num1, "*", num2, "=", multiply(num1, num2))
|
56 | 45 |
|
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
57 | 50 | elif choice == '4':
|
58 | 51 | print(num1, "/", num2, "=", divide(num1, num2))
|
59 |
| - |
60 |
| - elif choice == '5': |
61 |
| - print(num1, "to the power of", num2, "=", exponent(num1, num2)) |
62 |
| - |
63 | 52 | # check if user wants another calculation
|
64 | 53 | # break the while loop if answer is no
|
65 |
| - next_calculation = input("Do you want to do another calculation? (yes/no): ") |
| 54 | + next_calculation = input("Let's do next calculation? (yes/no): ") |
66 | 55 | if next_calculation == "no":
|
67 | 56 | break
|
68 | 57 |
|
69 | 58 | else:
|
70 |
| - print("Invalid input") |
| 59 | + print("Invalid Input") |
0 commit comments