0% found this document useful (0 votes)
4 views19 pages

While Loop

Uploaded by

Wahib Ahmed
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)
4 views19 pages

While Loop

Uploaded by

Wahib Ahmed
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/ 19

Agenda

• Why to use loops


• What are loops
• Types of loops in python
Nested conditionals
#example for nested if
num1=int(input("enter the first number:\n"))
num2=int(input("enter the first number:\n"))

if(num1==num2):
print("both the number are equal")
else:
if(num1>num2):
print("num1 is greater than num2")
else:
print("num2 is smaller than nunmber1")
Example pay roll
What are loops?

• Allow multiple times execution


• Condition defined in the beginning of the loop
• Condition false, the loop stops
ITERATION OR LOOPING

What is loop or iteration?


Loops can execute a block of code number of
times until a certain condition is met.
OR
The iteration statement allows instructions to
be executed until a certain condition is to be
fulfilled.

The iteration statements are also called as


loops or Looping statements.
example
#program Output:
Output 1: Output 2:
while loop - programs

BELOW AVERAGE PROGRAMS

1. Write a PYTHON program to print the natural


numbers up to n
2. Write a PYTHON program to print even
numbers up to n
3. Write a PYTHON program to print odd numbers
up to n
4. Write a PYTHON program to print sum of
natural numbers up to n
while loop - programs

AVERAGE PROGRAMS

5. Write a PYTHON program to print sum of odd


numbers up to n
6. Write a PYTHON program to print sum of even
numbers up to n
7. Write a PYTHON program to print natural
numbers up to n in reverse order.
8. Write a PYTHON program to print Fibonacci
series up to n
9. Write a PYTHON program find a factorial of
given number
for loop
Example: Output:

You might also like