DEV Community

Cover image for Cool Python Project 4: Calculator
Abhi Develops - SunTech
Abhi Develops - SunTech

Posted on

Cool Python Project 4: Calculator

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()
Enter fullscreen mode Exit fullscreen mode

I hope you enjoyed this Python project.

All the projects code in the series

Top comments (0)