0% found this document useful (0 votes)
19 views5 pages

CH-9 Flow of Control Notes-1

The document provides an overview of flow control in Python, detailing how programs can execute in a non-linear order using control structures such as if-else, for, while, and jump statements. It explains different types of statements in Python, including empty, simple, and compound statements, and outlines various conditional statements with examples. Additionally, the document includes activities and programming exercises to reinforce the concepts discussed.

Uploaded by

durgamehraaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

CH-9 Flow of Control Notes-1

The document provides an overview of flow control in Python, detailing how programs can execute in a non-linear order using control structures such as if-else, for, while, and jump statements. It explains different types of statements in Python, including empty, simple, and compound statements, and outlines various conditional statements with examples. Additionally, the document includes activities and programming exercises to reinforce the concepts discussed.

Uploaded by

durgamehraaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

THE NEW INDIAN SCHOOL W.L.L.

KINGDOM OF BAHRAIN
COMPUTER SCIENCE
CH-9 FLOW OF CONTROL
NOTES-1
CLASS : XI ABC

INTRODUCTION
• Generally a program executes from starting point to end point.
• Some program does not execute in order.
• As per the requirement, execution order of the program can be changed and it is also possible
to execute a program repeatedly.
• Python provides control structures to manage the order of execution of a program, which are
if-else, for, while and jump statements like break, continue.
TYPES OF STATEMENTS
In Python, statements are of 3 types-
» Empty Statements
• pass
» Simple Statements (Single Statement)
name=input (“Enter your Name “)
print(name) etc.
» Compound Statements
<Compound Statement Header>:
<Indented Body containing multiple simple /compound statements>
Here, Header line starts with the keyword and ends at colon (:).
The body consists of more than on simple Python statements or compound
statements.
PYTHON CONDITIONAL STATEMENTS
Conditional Statements are features of a programming language, which perform different
computations or actions depending on whether the given condition evaluates to true or false.
Conditional statements in python are of 4 types
• if statement
• if else statement
• if elif statement
• Nested if else
If Statement:
In Python, if statement is used to select statement for processing. If execution of a statement is to
be done on the basis of a condition, if statement is to be used. Its syntax is-
if <condition>:
statement(s)
Example:
For example consider the code given below
if (percentage > 33):
print (“Pass”)
Explanation : In the above code if value of percentage is above 33 then only the message “Pass” will
be printed.
if-else Statement
If out of two statements, it is required to select one statement for processing on the basis of a
condition, if-else statement is to be used. Its syntax is-
if <condition>:
statement(s) when condition is true
else:
statement(s) when condition is false
For example consider the code given below
if (percentage > 33):
print (“Pass”)
else:
print(“Fail”)
Explanation : In the above code if value of percentage is above 33 then only
the message “Pass” will be printed otherwise it will print “Fail”

Activity
1. Write a program that prompts the user to input a number and display if the number is even or odd.
2. Write a program that prompts the user to input two integers and outputs the largest.
3. Write a python program that asks the user to enter a length in cm. If the user enters a negative length
the program should tell the user that the entry is invalid. Otherwise , the program should convert the
length to inches and print out the result. There are 2.54 cm in an inch.
4. Input three angles and determine if they form a triangle or not.(condition is
angle1+angle2+angle3=180)
ACTIVITY ANSWERS:
1. num = int (input ("Enter any number "))
if (num % 2) == 0:
print ("The number is even")
else:
print ("The provided number is odd")

2. num1= int(input("Enter number 1: "))


num2= int(input("Enter number 2: "))
if num1>num2:
print(num1," is greater than ",num2)
else:
print(num2," is greater than ",num1)

3. cm = int(input("Enter length in cm : "))


if cm < 0:
print("invalid entry")
else:
print(cm/2.54, "inches")

4. a= int(input("Enter First Side of a Triangle : "))


b = int(input("Enter Second Side of a Triangle : "))
c = int(input("Enter Third Side of a Triangle : "))
if a + b > c and a + c > b and c + b > a:
print("Triangle can be formed !")
else:
print("Triangle cannot be formed")

if-elif Statement
If out of multiple statements, it is required to select one statement for processing on the basis of a
condition, if-elif statement is to be used. Its syntax is-
if <condition1>:
statement(s) when condition1 is True
elif <condition2>:
statement(s) when condition2 is True
elif <condition3>:
statement(s) when condition3 is True
else:
statement(s) when all conditions are False
Examples:
percentage=float(input(“ Enter Percentage”))
if (percentage >90):
print(“Outstanding”)
elif (percentage >80):
print (“Excellent”)
elif (percentage >70):
print (“VeryGood”)
elif (percentage >60):
print (“Good”)
elif (percentage >33):
print (“Pass”)
else
print(“Fail”)
Explanation : In the above code
if value of percentage is above 90 then it will print “Outstanding”
if value of percentage is above 80 then it will print “Excellent”
if value of percentage is above 70 then it will print “Very Good”
if value of percentage is above 60 then it will print “Good”
if value of percentage is above 80 then it will print “Pass”
if no condition is true then it will print “Fail”
In above code only 1 condition can be True at a time if no condition is True then else statement will be
executed.
Activity
1. The marks obtained by a student in 3 different subjects are input by the user. Your program should
calculate the average of subjects and display the grade. The student gets a grade as per the following
rules:
Average Grade
90-100 A
80-89 B
70-79 C
60-69 D
0-59 F
(Refer text book Page No. 326 program 10)
2. Write a program to calculate BMI….. (Refer text book Page No. 318 program 27)
3. Write a Program to find biggest among 3 Numbers
b = int(input('Enter second number : '))
c = int(input('Enter third number : '))
if a > b and a > c:
largest = a
elif b > a and b > c:
largest = b
else:
largest = c
print(largest, "is the largest of three numbers.")
4. Write a Python program to check whether a given number is positive, negative or zero.
num = float(input("Enter a number: "))
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
5. Write a program that prompts the user to input a number. Program should display the corresponding
days to the number. For example if user type 1 the output should be Sunday. If user type 7 the output
should be Saturday. (Try yourself)

6. Write a program that prompts the user to input number of calls and calculate the monthly telephone
bills as per the following rule:

Minimum Rs. 200 for up to 100 calls.


Plus Rs. 0.60 per call for next 50 calls.
Plus Rs. 0.50 per call for next 50 calls.
Plus Rs. 0.40 per call for any call beyond 200 calls.
TextBook solved problems: Qn. 1,7
Unsolved Problems: 1-7

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy