Class 11 - Presentation # 4 - Flow of Control
Class 11 - Presentation # 4 - Flow of Control
XI
Empty Statement
The simplest statement is the empty statement i.e. a statement which does nothing.
It is written as:
pass
Whenever the interpreter encounters a pass statement, Python does nothing and
simply moves to the next statement in the flow of control. The pass statement is a
do nothing statement i.e. empty statement or a null operation statement.
2
XI
Simple Statement
Any single executable statement is a simple statement in Python. Simple statement
A simple example is
3
XI
Compound Statement
A compound statement is a group of statements executed as one unit. The compound
4
XI
Compound Statement
In Python, indentation is used to declare a block. If two statements are at the same
Generally four white spaces are used for indentation and is preferred over tabs.
Indentation is the most used part of the python language since it declares the block
of code.
All the statements of one block are intended at the same level indentation.
5
XI
Statement Flow Control
In a program, statements may be executed sequentially, selectively or iteratively.
6
XI
Sequence
The sequence construct means the
7
XI
Selection
The selection construct means the
8
XI
Selection
Python if statement supports selection.
● To input the marks of a student, and if the marks are above 75, the
message should display that the child has performed ‘well’ otherwise it
should display that ‘An improvement is needed’.
9
XI
Iteration
The iteration construct means repetition of a set of
10
XI
Conditional Statement using if
The if statements are the conditional statements in Python that implement
11
XI
Conditional Statement using if
For example:
12
XI
Conditional Statement using if
For example:
13
XI
Conditional Statement using if... else
if else statement : This form of statement checks for the test condition. If the
<Statement1> print("Good")
else:
else:
<Statement2>
print("Can do better")
14
XI
Conditional Statement using if... else
For example:
15
XI
Conditional Statement using if..elif..else
<Statement1> print("Good")
... else:
else: print("You need to work hard")
<StatementN>
16
XI
Question 1
Write a Python code to accept Age and Name from the user, and display a message
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday
7 Sunday
18
XI
Question 2
Write a program to input the day number and print week day.
20
XI
Question 4
Write a program to check whether an alphabet is vowel or consonant.
21
XI
Question 5
Write a program to check whether a character is uppercase or lowercase alphabet.
22
XI
Question 6
Write a program to input two numbers and determine Enter the first number:6
Enter the second number:2
Another run
num1=int(input("Enter the first number:")) Enter the first number:9
num2=int(input("Enter the second number:")) Enter the second number:18
if num1%num2==0: 18 is a multiple of 9
print(num1, " is a multiple of ",num2)
elif num2 % num1 == 0: Another run
print(num2, " is a multiple of ",num1) Enter the first number:7
Enter the second number:88
else:
7 and 88 are not multiples
print(num1," and ", num2," are not multiples")
23
XI
Programs
1. Write a program to Input a number and display if the number entered is even or
24
XI
Program
5. Write a program to input marks of five subjects Physics, Chemistry, Biology,
>= 90 A
>= 80 B
>=70 C
>=60 D
>=40 E
< 40 F
25
XI
6. Write a program to input electricity unit charge and calculate the total electricity
26
XI
7.Write a program to input basic salary of an employee and calculate gross salary
28
XI
Question 2
Write a menu driven program to calculate the area of a 1. Calculate Area of Circle
2. Calculate Perimeter of Circle
30
XI
Question 4 - Program to calculate grade
Math module imported to use sqrt() and fabs()
33
XI
Question 7
basic=float(input("Enter the basic salary:")) Enter the basic
salary:12000
34
XI
Nested if
35
XI
Nested if
age = int(input("Enter your age : "))
Statements /Suite A:
Statements/Suite B
Statements/Suite C
Statements/Suite D
Statements/Suite E
Statements/Suite F
Statements/Suite G
37
XI
Indentation
if a<b:
print(“A is smaller than B”) Both statements are at
print(“B is greater than A”) same indent level
The above code will print both statements if the condition “a<b” is true.
38
XI
Indentation
● One statement is linked with if
if 5>40:
print(“5 is not smaller than 40”) No output will
print(“Done”) be shown
39
XI
Indentation
● Invalid indentation is a syntax error
● If you have only one statement to execute, you can put it on the same line
as the if statement.
40
XI
Programs
1. Write a Menu driven program to calculate the surface area and volume of a
41
XI
Find syntax error(s), if any, in the following:
1. 2.
43
XI
Find the output:
var=100
45
XI
Find output of the following:
What will the program print if the
46
XI
Solution
(a) Wow 3
47
XI
Find output of the following:
x=0 x=0
48
XI