Hi Everyone! Welcome to Cool Python Projects!
In this post I will be showing you how to make a Calculator in Python. Please remember to follow me to stay updated on any new projects.
Python Code:
def divide (user_number_3, user_number_4):
result1 = user_number_3 / user_number_4
return result1
def add (user_number_3, user_number_4):
result2 = user_number_3 + user_number_4
return result2
def multiply (user_number_3, user_number_4):
result3 = user_number_3 * user_number_4
return result3
def subtraction (user_number_3, user_number_4):
result4 = user_number_3 - user_number_4
return result4
def main ():
user_choice = input("Do you want to a)add or b)multiply c)divide d) subtract - Enter a, b , c, or d ")
user_number_1 = int(input('Enter first number '))
user_number_2 = int(input('Enter second number '))
if user_choice == 'a':
result = add(user_number_1, user_number_2)
print('The result is: {}'.format(result))
print("Hope you had fun with our calculator!")
if user_choice == 'b':
result = multiply(user_number_1, user_number_2)
print('The result is: {}'.format(result))
print("Hope you had fun with our calculator!")
if user_choice == 'c':
result = divide(user_number_1, user_number_2)
print('The result is: {}'.format(result))
print("Hope you had fun with our calculator!")
if user_choice == 'd':
result = subtraction(user_number_1, user_number_2)
print('The result is: {}'.format(result))
print("Hope you had fun with our calculator!")
main()
I hope you enjoyed this Python project.
Top comments (0)