0% found this document useful (0 votes)
1 views9 pages

Python Loops

The document discusses control statements in Python, focusing on selection statements (like 'if') and looping statements ('while' and 'for'). It provides examples of programs that utilize these control statements to perform various tasks, such as checking if a number is odd or even, determining voting eligibility, and calculating grades based on marks. The document serves as a guide for implementing control flow in Python programming.

Uploaded by

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

Python Loops

The document discusses control statements in Python, focusing on selection statements (like 'if') and looping statements ('while' and 'for'). It provides examples of programs that utilize these control statements to perform various tasks, such as checking if a number is odd or even, determining voting eligibility, and calculating grades based on marks. The document serves as a guide for implementing control flow in Python programming.

Uploaded by

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

Python Loop

Dr. Upesh Patel & Dr. Trushit Upadhyaya


CHAROTAR UNIVERSITY OF SCIENCE & TECHNOLOGY
Control Statement In Python

• Python statements are executed one by one the same order as they appear in the
program. There may be some requirement when we would like to execute the
statements based upon a condition. Even there may be some situation where we
want to execute a single statement or multiple statement (Block of statements) “n”
times till the condition is true. In order to control the flow of execution of the
program Python provides us Control Statements.

• There are two types of control statements:


• 1. Selection statement
• if
• 2. Looping condition
• while or for
Control Statement In Python

• 1. Selection Statement:
• Selection statements are used to select the statements based on a
condition. If there is some conditions based upon which it is decided
that whether a statement will be executed or not, then it is called
selection statement. Python provides “if” selection statement.

• 2. Looping Statement:
• Looping statements are used to execute a single statement or a block of
statement (multiple statement) “N” times till the condition is true.
Looping statement keeps on executing the statement till the given
condition is true. It stops working at the moment when the condition
becomes false.
Control Statement In Python
Programs using IF/ELIF/ELSE condition
• Write a program to check whether a number is ODD/EVEN
• Write a program to check a person can vote or note.
• Write a program to check maximum number between two numbers
• Write a program to check maximum number between three numbers
• Write a program to check if a given number is positive, negative or zero
• Write a program to find the middle number in a group of three numbers
• Write a program to calculate total marks in 5 course (Max marks=100),
percentage and division of grades.
Percentage >=80 Grade A Percentage >=40 Grade C
Percentage >=60 Grade B Percentage < 40 Failed
• Write a program to print absolute value of a number entered by user.
e.g.-
INPUT :1 OUTPUT: 1
INPUT : -1 OUTPUT: 1
• A student will not be allowed to sit in exam if his/her attendance is less
than 75%. Take following input from user
• Number of classes held
• Number of classes attended.
• And print percentage of class attended
• Is student is allowed to sit in exam or not.
• Modify the above question to allow student to sit if he/she has medical
cause. Ask user if he/she has medical cause or not ( 'Y' or 'N' ) and print
accordingly.
• A shop will give discount of 10% if the cost of purchased quantity
is more than 1000. Ask user for quantity.
Suppose, one unit will cost 100.
Judge and print total cost for user.
• Accept any city from the user and display monument of that city.
City Monument
Delhi Red Fort
Agra Taj Mahal
Jaipur Jal Mahal
Solution

You might also like