PROGRAMMING CONSTRUCT (Flow of Control)

The flow of activity through the program code is called the flow of control. There are three main types of control flows that occur. These are:- Sequential ,  Conditional or Selection ,  Repetition or Loop

In a program, statement may be executed sequentially, selectively or iteratively.

Sequence - The sequence construct means the statements are being executed sequentially from top to bottom.

Selection or Conditional- The selection construct means the execution of statement(s) depending upon a condition test. It is also known as decision construct.

Repetition or loop - The Iooping statement means repetition of a set of statements depending upon a condition-test.

Repetition statement is also called iteration statement.

Identifier forming rules of Python –

• The first character must be a letter; the underscore(_) counts as letter. • Upper and lower- case letters are different. • The digits 0 through 9 can be part of the identifier except for the first character. • An identifier must not be a keyword. • An identifier cannot contain any special character except for underscore (_). • Identifiers are unlimited in length. Python is case sensitive as it treats upper and lower –case character differently.

Some valid Identifier – Myself   num1   _roll  _Ht13_h  Myfile  file13
Some invalid Identifier – Data-rec  break  29click  my.file  if   else   while   roll*no

Simple if- The simple if checks a condition, if the condition is true a set of statement(s) are executed and if the condition is false then nothing happens.

if…else – In if---else if the test condition is true the whatever we have written between if and else are executed and if the condition is false the then statements after else are executed.

if--- elif - In if--- elif statement we can check multiple test conditions. (If none of the considtions are satisfied then he statements after else are executed)

A flowchart is a diagram or map showing the steps taken to reach a certain result.
A flowchart is used to refer to the drawing of figures to solve any problem.
It is a good habit to make flowcharts as it makes easy to write a computer program.

Myper = int (input(“enter percentage”))

if ( Myper >= 33):
   print(“You are PASS”)
else:
  print(“Sorry Not Promoted”)


Python Loops

Python has two loop commands: while loops and for loops

Looping statements are those statements that are repeated continuously untill a given condition is satisfied.

Structure/ Elements of loop-  All the loops will have the following elements. Initialization ,  Condition/ Expression Test, Update and  Body of loop

The while Loop

With the while loop we can execute a set of statements as long as a condition is true.
When the Condition becomes false , program control passes to the line immediately following the loop.
The else statement is optional and executes the program statements when the condition becomes false.
If you do not mention the else statement and when the condition is tested and the result is False , the loop body will be skipped and the first statement after while loop will be executed.
To exit from the loop you can use break statement at any place in between the loop.

Write a program in Python to print first 10 natural number and their sum.

Write a program in Python to print the following pattern:

*****
****
***
**
*


for loop

A for loop is used for iterating over a sequence (that is either a list, a tuple , a dictionary, or a string).

This is less like the for keyword in other programming language, and works more like an iterator method as found in other object-orientated programming languages.

With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.

Print each fruit in a fruit list:

fruits = ["apple", "banana", "cherry"]
for x in fruits:
  print(x)

Tea Or Coffee

Python Downloads

DataFrame
Reindexing and Label Alteration
Function Application –Python pandas
Bar Charts and Histograms and Quantile
Plottint with PyPlot-2

 

Ways to Keep Your Brain Healthy