|
| 1 | +def add(a, b): |
| 2 | + return a + b |
| 3 | + #Evaluates a + b and returns the INTEGER result back to the point where this function was called from. |
| 4 | + |
| 5 | +def sub(a, b): |
| 6 | + return a - b |
| 7 | + |
| 8 | +def mult(a, b): |
| 9 | + return a * b |
| 10 | + |
| 11 | +def div(a, b): |
| 12 | + return a / b |
| 13 | + |
| 14 | +def remainder(a,b): |
| 15 | + return a % b |
| 16 | + |
| 17 | +print(" ** CALCULATOR ** ") |
| 18 | +print("Enter two numbers") |
| 19 | +a = input() |
| 20 | +b = input() |
| 21 | + |
| 22 | +#Suppose user enters 3 and 5, Then a = "3", b = "5", "3" and "5" are strings |
| 23 | +#But we need a = 3, and not "3" and b = 5, and not "5", so it becomes integers and we can perform arithmetic operations. |
| 24 | + |
| 25 | +a = int(a) # This line converts whatever is stored in a to INTEGER Type and assigns that value to a. |
| 26 | +b = int(b) # This line converts whatever is stored in b to INTEGER Type and assigns that value to b again. |
| 27 | + |
| 28 | +#SO simply put, int function converts variables to INTEGER data type |
| 29 | +# And similiarly, there is an str() function which converts variables to STRING data type |
| 30 | + |
| 31 | +print("\n\nResults!") |
| 32 | + |
| 33 | +# Suppose I entered a=1, b=2 then this happens, |
| 34 | + |
| 35 | +print(add(a,b)) #Addition, add(a,b) becomes --> 3, 3 gets printed on screen. |
| 36 | +print(sub(a,b)) #Subtraction, sub(a,b) --> -1 |
| 37 | +print(div(a,b)) #Division, div(a,b) --> 0 |
| 38 | +print(mult(a,b)) #Multiplication, mult(a,b) -> 2 |
| 39 | +print(remainder(a,b)) #Remainder, remainder(a,b) -> 1 |
0 commit comments