Loops in python
In Python, there are two types of Loops
- For Loop
- While Loop
1. For Loop
#program for loops in python
n=5
for i in range(n):
print(‘This is For Loop’)
This is For Loop
This is For Loop
This is For Loop
This is For Loop
This is For Loop
#program for loops in python
n=7
for i in range(n):
print(i)
0
1
2
3
4
5
6
for i in range(2,n):
print(i)
2
3
4
5
6
iterating over the List in python
print(“List Iteration”)
list = [ “Python”, “Java”, “C”, “PHP”]
for i in list:
print( i )
Python
Java
C
PHP
iterating over the String in python
print(” String Iteration “)
s=”Python”
for i in s:
print( i )
P
y
t
h
o
n
iterating over the Tuple in python
print(” Tuple Iteration “)
t=(“MySQL”, “Oracle”, “MongoDB”)
for i in t:
print( i )
MySQL
Oracle
MongoDB
2. While Loop
n=0
while(n<4):
print(‘Hello Wolrd’)
n=n+1
Hello World
Hello World
Hello World
Hello World
Python Program to add two numbers
Python program to find Area of Square
Python program to find Area of Triangle
Python program to swap two variables
Python program to convert Celsius to Fahrenheit
Python program to generate Random Number
Python program to convert Miles to Kolometers
Python program to find Largest of 2 numbers
Python program to check if number is Odd or Even
Python program to check if number is Positive Negative or Zero
Python program to check Leap Year
Types of Loop in Python
Python program to check Prime Number
Python program to Calculate Sum of N Natural Numbers
Python program to find sum of All Even Number between 1 to 10
Python program to find sum of All Odd Number between 1 to 10
Python program to check Armstrong Number