def calculate(): number_1 = int(input('Enter your first number: ')) number_2 = int(input('Enter your second number: ')) operation = input(''' Enter an operator: + for addition - for subtraction * for multiplication / for division ''') if operation == '+': sum = number_1 + number_2 print('{} + {} = '.format(number_1, number_2)) print(sum) elif operation == '-': diff = number_1 - number_2 print('{} - {} = '.format(number_1, number_2)) print(diff) elif operation == '*': product = number_1 * number_2 print('{} * {} = '.format(number_1, number_2)) print(product) elif operation == '/': quotient = number_1 / number_2 print('{} / {} = '.format(number_1, number_2)) print(quotient) else: print('You have not typed a valid operator, please run the program again.') calculate() def recal(): c = int(input('Enter the number: ')) operation2 = input(''' Enter an operator: + for addition - for subtraction * for multiplication / for division ''') if operation2 == '+': answer = sum + c print('{} + {} = '.format(sum, c)) print(answer) elif operation2 == '-': answer2 = diff - c print('{} - {} = '.format(diff, c)) print(answer2) elif operation2 == '*': answer3 = product * c print('{} * {} = '.format(product, c)) print(answer3) elif operation2 == '/': answer4 = quotient / c print('{} / {} = '.format(quotient, c)) print(answer4) else: print('You have not typed a valid operator, please run the program again.') while True: calc_again = input(''' Do you want to compute again? Please type Y for YES or N for NO. Type C if you want to continue.''') if calc_again == 'Y': calculate() elif calc_again == 'N': print('Thank You') elif calc_again == 'C': recal() else: print('END')
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)