Giter VIP home page Giter VIP logo

basic-calculator-program-using-python's Introduction

Basic-Calculator-Program-using-Python

This program is just to understand the working and use of functions and try-except in Python

Functions

A function is a block of code which only runs when it is called.You can pass data, known as parameters, into a function.A function can return data as a result.

Calling a Function

Function can be called anytime by using the function name followed by parenthesis. EXAMPLE: my_function()

Arguments or Parameters

Information can be passed into functions as arguments. Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma. EXAMPLE: def my_function(name,age):

If 2 arguments are given the function also expects exactly 2 arguments, else error will be shown.

Try Except

#Try

The try block lets you test a block of code for errors.

#Except

The except block lets you handle the error.

#Finally (Using of finally is not shown in the above code)

The finally block lets you execute code, regardless of the result of the try- and except blocks.

#Exception Handling

When an error occurs ,Python will normally stop and generate an error message.

These EXCEPTIONS can be handled using the TRY STATEMENT. Since the try block raises an error, the except block will be executed (in except block we gives what to be shown when error occurs like print somthing or to do something). Without the try block, the program will crash and raise an error.

#Many Exceptions

You can define as many exception blocks as you want,e.g. if you want to execute a special block of code for a special kind of error. This can be done by making a new except block blow the previos except block.

#Else You can use the else keyword after exception to define a block of code to be executed if no errors were raised.

basic-calculator-program-using-python's People

Contributors

fahad-sajeem 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.