Python Loops
Python Loops
• 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.
• 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