Code Monkey home page Code Monkey logo

python-program-for-basic-calculator-operations's Introduction

Python-Program-for-Basic-Calculator-Operations

A Function is the simple callable object in python. A function can accept some arguments and possibly return some object. The following python code represents the basic calculator operation like addition, subtraction, multiplication and division. The code is well organized with different functions.

menu() function prints the main menu, and prompts for a choice

def menu(): #print what options you have print "Welcome to calculator in Python" print "your options are:" print " " print "1) Addition" print "2) Subtraction" print "3) Multiplication" print "4) Division" print "5) Quit calculator" print " " return input ("Choose your option: ")

this adds two numbers given

def add(a,b): print a, "+", b, "=", a + b

this subtracts two numbers given

def sub(a,b): print b, "-", a, "=", b - a

this multiplies two numbers given

def mul(a,b): print a, "*", b, "=", a * b

this divides two numbers given

def div(a,b): print a, "/", b, "=", a / b

NOW THE PROGRAM STARTS, AS CODE IS RUN

loop = 1 choice = 0 while loop == 1: choice = menu() if choice == 1: add(input("Add this: "),input("to this: ")) elif choice == 2: sub(input("Subtract this: "),input("from this: ")) elif choice == 3: mul(input("Multiply this: "),input("by this: ")) elif choice == 4: div(input("Divide this: "),input("by this: ")) elif choice == 5: loop = 0

print "Thankyou for using calculator!"

End of the program

OUTPUT:

Welcome to calculator in Python your options are:

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division
  5. Quit calculator

Choose your option: 1 Add this: 25 to this: 35 25 + 35 = 60 Welcome to calculator your options are:

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division
  5. Quit calculator

Choose your option: 3 Multiply this: 15 by this: 10 15 * 10 = 150 Welcome to calculator your options are:

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division
  5. Quit calculator

Choose your option: 5 Thankyou for using calculator!

python-program-for-basic-calculator-operations's People

Contributors

buzman01 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.