def addition(number, number2, mathematic_assignment):
sum_value = number + number2
return f'The sum of {number} {mathematic_assignment} {number2} is {sum_value}'
def subtraction(number, number2, mathematic_assignment):
subtract_value = number - number2
return f'The subtraction of {number} {mathematic_assignment} {number2} is {subtract_value}'
def multiply(number, number2, mathematic_assignment):
multiplied_value = number * number2
return f'The result of multiplying {number} {mathematic_assignment} {number2} is {multiplied_value}'
def division(number, number2, mathematic_assignment):
divided_value = number / number2
return f'The division of {number} {mathematic_assignment} {number2} is {round(divided_value)}'
def run_program():
print("Welcome to the base calculator")
is_running = True
while is_running:
first_number = int(input('Please provide the first number: '))
second_number = int(input('Please provide the second number: '))
mathematic_assignment = input('Please provide mathematical preference: \n+\n-\n*\n/\n')
if mathematic_assignment == '+':
print(addition(first_number, second_number, mathematic_assignment))
elif mathematic_assignment == '-':
print(subtraction(first_number, second_number, mathematic_assignment))
elif mathematic_assignment == '*':
print(multiply(first_number, second_number, mathematic_assignment))
elif mathematic_assignment == '/':
print(division(first_number, second_number, mathematic_assignment))
else:
print('There can be an error in the output, you must only put in "+", "-", "*", "/"')
choice = input("Press 'q' to quit or anything to go on: ")
if choice == 'q':
print('The program will now quit')enter code here
is_running = False
if __name__ == '__main__':
run_program()enter code here
The following code is an example of a base calculator made out of functions. However, the problem I have been struggling with is starting the calculator where the first number is the previous result, so you only get the second number and the mathematical operation required (so if 5+5 is 10 then the next time you run the code (using the while loop) now the first number is 10 + {another number}).
As you can see it's all ready except the following challenge. I am more than sure I can tackle this on my own without the functions however I want to know how functions operate and learn them in more detail. I would really appreciate an answer