Calculator

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

def calculator():

operation = int(input("Please type your choice:\n1


Addition \n2. Subtraction \n3. Multiplication \n4. /
Division\n"))
if(operation > 4 or operation <1):
print ("Invalid operator!")
else:
number_1 = int(input('Please enter the
first number: '))
number_2 = int(input('Please enter the
second number: '))
if operation == 1:
print('{} + {} = {} '.format(number_1,
number_2, number_1 + number_2))
elif operation == 2:
print('{} - {} = {}'.format(number_1,
number_2,number_1 - number_2))
elif operation == 3:
print('{} * {} = {}'.format(number_1,
number_2, number_1 * number_2))
else:
print('{} / {} = {}'.format(number_1,
number_2, number_1 / number_2))
again()
def again():
calc_again = input("Do you want to
calculate again? (Y for YES or N for NO.)")
if calc_again.upper() == 'Y':
calculator()
elif calc_again.upper() == 'N':
print('Closing calculator.')
else:
again()
calculator()

You might also like