Python Programming Basics

Let’s Start :

Addition Of N Numbers

Program to Calculate the sum of N inputs of from the user:


Conditional Branching

Conditional branching is used to make the system execute one set of statements and skip another set of statements, based on a

In Python conditional branching is done using the “if”- “elif” — “else” statement.

if statement:

if statement is used for conditional branching of program code.

It has:

  1. A criteria
  2. A block of code associated with it

System evaluates the criteria and results into a boolean. When the boolean value is True then the associated block of code executes, otherwise not.

Optionally as “if” statement has:

  1. An “elif” statement
  2. An “else” statement

“elif” statement:

An elif statement represents a secondary criteria based on the “FALSE” state of a primary criteria represented using an “if” or an “elif” statement.

System evaluates an “elif” only when the criteria that precede it is “FALSE”.

On evaluation if its (elif) result is “TRUE” then its (elif) block of code executes, otherwise not. else statement is optionally associated with elif.

“else” statement:

else statement is optionally associated with an “if” statement or an “elif” statement.

It (else) is associated with the FALSE state of the proceeding condition. Hence it executes only when the proceeding criteria evaluates to false.


Program a Basic Arithmetic Calculator