Posts

Showing posts from April, 2020

Looping statement in python

Image
Basic looping structure in python Python supports basic loop structures through iterative statements.iterative statements are decision control statements that are used to repeat the execution of a list of statements.python language supports two types of iterative statements - while loop and for loop. While loop: The while loop provides a mechanism to repeat one or more statements while a particular  condition is true. Syntax: statement x while  (condition):     block of statement statement y  A while loop is also referred to as a top-checking loop since control condition is places as the first line of the code. if the condition evaluates to false, then the statement enclosed in the loop are never executed ... now look following examples: Q. write a program in python to calculate the sum and average of first 10 number. i =  0 s =  0 while (i<= 10 ):      s = s+i      i=i+ 1 avg =  float (s)/ 10 print ( "the sum of first 10

Decision making statement in python

Image
Decision making statement in python In this statement we can take a decision for executing block of statement.if in this case condition is checked.if condition is true then the true part will execute,otherwise false part will execute.        There are four types of decision making statement. (1) simple if statement/single alternative if statement. (2) if-else statement/double alternative if statement. (3) if-else-if statement/else if ladder statement. (4) Nested if statement/compound if statement. (1)simple if statement/single alternative if statement  In this statement if condition is true then true part will execute otherwise no action will generate.  Syntax: if  test expression:     Statement 1     Statement 2     Statement 3    ---------------    ---------------     Statement n Statement x Examples: if  ( age>=18) :    print( "You are eligible for vote" ) (2) if-else statement/double alternative if statement In this statement if co