[go: up one dir, main page]

0% found this document useful (0 votes)
29 views2 pages

Welcome: # Don't Forget To Call The Function

The document contains Python code that defines functions to welcome users to a calculator program, get user input for mathematical operations and numbers, perform the calculation, and allow users to calculate again or exit. The calculate() function gets operator and number inputs and performs addition, subtraction, multiplication or division based on the operator. It calls the again() function to allow another calculation.

Uploaded by

Sam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Welcome: # Don't Forget To Call The Function

The document contains Python code that defines functions to welcome users to a calculator program, get user input for mathematical operations and numbers, perform the calculation, and allow users to calculate again or exit. The calculate() function gets operator and number inputs and performs addition, subtraction, multiplication or division based on the operator. It calls the again() function to allow another calculation.

Uploaded by

Sam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

def welcome():

print('''

Welcome to Calculator

''')

...

# Don’t forget to call the function

welcome()

calculate()

def calculate():
operation = input('''
Please type in the math operation you would like to complete:
+ for addition
- for subtraction
* for multiplication
/ for division
''')

number_1 = int(input('Please enter the first number: '))


number_2 = int(input('Please enter the second number: '))

if operation == '+':
print('{} + {} = '.format(number_1, number_2))
print(number_1 + number_2)

elif operation == '-':


print('{} - {} = '.format(number_1, number_2))
print(number_1 - number_2)

elif operation == '*':


print('{} * {} = '.format(number_1, number_2))
print(number_1 * number_2)

elif operation == '/':


print('{} / {} = '.format(number_1, number_2))
print(number_1 / number_2)

else:
print('You have not typed a valid operator, please run the
program again.')

# Add again() function to calculate() function


again()

def again():
calc_again = input('''
Do you want to calculate again?
Please type Y for YES or N for NO.
''')

if calc_again.upper() == 'Y':
calculate()
elif calc_again.upper() == 'N':
print('See you later.')
else:
again()

calculate()

You might also like