Uploaded by saipyaephyothar

python lecture2

advertisement
Python
Programming
Python Control Flow Statements
Conditional statements
#Task 1
#Task 2
In Python, the if-elif-else condition statement has an elif blocks to chain multiple conditions one after another. This is useful when yo
Chain multiple if statement in Python
• In Python, if-elif-else condition statement has an elif blocks to chain
multiple conditions one after another.
• This is useful when you need to check multiple conditions.
Nested if-else statement
• In Python, the nested if-else statement is an if statement inside
another if-else statement. It is allowed in Python to put any number
of if statements in another if statement.
Iterative statements
• Python provides us the following two loop statement to perform
some actions repeatedly
• for loop
• while loop
Python for loop
Python while loop
Exercise
Example: Print first 10 numbers using a
for loop
Example: Calculate the square of each
number of list
Example: Calculate the average of list of numbers
•
Example: Print all even and odd numbers
• Example: Print numbers less than 5
Download