#### For loop

for loop is the most comfortable loop. It is also an entry check loop. The condition is checked in the beginning and the body of the loop(statements-block 1) is executed if it is only True otherwise the loop is not executed.

Syntax:

for counter_variable in sequence:

statements-block 1

[else: # optional block

statements-block 2]

The counter_variable mentioned in the syntax is similar to the control variable that we used in the for loop of C++ and the sequence refers to the initial, final and increment value. Usually in Python, for loop uses the range() function in the sequence to specify the initial, final and increment values. range() generates a list of values starting from start till stop-1.

Example : #program to illustrate the use of for loop - to print single digit even number

for i in range (2,10,2):

print (i, end=' ')

Output:

2 4 6 8

Example  : #program to illustrate the use of for loop - to print single digit even number with else part

`for i in range(2,10,2):print (i,end=' ')else:print ("\nEnd of the loop")`

Output:

2 4 6 8

End of the loop

Example : # program to calculate the sum of numbers 1 to 100

`n = 100sum = 0for counter in range(1,n+1):	sum = sum + counterprint("Sum of 1 until %d: %d" % (n,sum))`

Output:

Sum of 1 until 100: 5050

Example : program to illustrate the use of string in range() of for loop

`for word in 'Computer':print (word,end=' ')else:print ("\nEnd of the loop")`

Output

C o m p u t e r

End of the loop

Qus. 1 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">x = 'abcd'<br></span><span style="font-size: 14px;">for i in range(x):<br></span><span style="font-size: 14px;">&nbsp; &nbsp; print(i)</span></pre>

1. a b c d
2. 0 1 2 3
3. error
4. none of the mentioned
Qus. 2 : <p>What will be the output of the following Python code?</p><pre>for i in range(0):<br>&nbsp; &nbsp; print(i)</pre>

1. 0
2. no output
3. error
4. none of the mentioned
Qus. 3 : <p>What will be the output of the following Python code?</p><pre>for i in range(2.0):<br>&nbsp; &nbsp; print(i)</pre>

1. 0.0 1.0
2. 0 1
3. error
4. none of the mentioned
Qus. 4 : <p>What will be the output of the following Python code?</p><pre>for i in range(int(2.0)):<br>&nbsp; &nbsp; print(i)</pre><div><br></div>

1. 0.0 1.0
2. 0 1
3. error
4. none of the mentioned
Qus. 5 : <p>What will be the output of the following Python code snippet?</p><pre>x = 2<br>for i in range(x):<br>&nbsp; &nbsp; x += 1<br>&nbsp; &nbsp; print (x)</pre>

1. 0 1 2 3 4 …
2. 3 4
3. 0
4. error
Qus. 6 : Which is the most comfortable loop?

1. do..while
2. while
3. for
4. if..elif
Qus. 7 : <p>What will be the output after the following statements?</p><pre>for i in range(1,6):<br>&nbsp; &nbsp; print(i, end='')<br>&nbsp; &nbsp; if i == 3:<br>&nbsp; &nbsp; &nbsp; &nbsp; break</pre>

1. 1 2
2. 1 2 3
3. 1 2 3 4
4. 1 2 3 4 5
Qus. 8 : Operations to be repeated a certain number of times are done by

1. Selection
2. Sequential
3. Simple
4. Loop
Qus. 9 : The for loop in Python is an ____ .

1. Entry Controlled Loop
2. Exit Controlled Loop
3. Both of the above
4. None of the above
Qus. 10 : A loop block in python starts with a.. -

1. ; (semicolon)
2. ,(Comma)
3. : (colan)
4. None of these
Qus. 11 : ___ in Python is a counter-controlled loop.

1. for
2. while
3. Both A and B
4. None of the above
Qus. 12 : How many times will loop run? for a in "56247839"

1. 11
2. 8
3. 1
4. 0

#### Programs

python Program to obtain temperature in Celsius and convert it into Fahrenheit

pythoon program to read todays date only date Part from user Then display how many days are left in the current month

python program to print the area of circle when radius of the circle is given by user

python program to print the volume of a cylinder when radius and height of the cylinder is given by user

python program that asks your height in centimeters and converts it into foot and inches

python program accept three side of triangle and find area of a triangle

python program to input principle amount,rate time and calculate simple interes

python program to read a number in n and prints n2 n3 n4

python program to calculate compound simple interest after taking the principle rate and time

python program to take two numbers and check that the first number is fully divisible by second number or not

python program which take value of x y z from the user and calculate the equation

python program to take the temperatures of all 7 days of the week and displays the average temperature of that week

python program to check the given year is leap year or not

python program that searches for prime numbers from 15 through 25

python program to test if given number is prime or not

python program to compute the result when two numbers and one operator is given by user

python program to calculate the roots of a given quadratic equation.

python program to input a digit and print it in words

python program to check whether square root of a given number is prime or not

python program to print first n odd numbers in descending order.

python program to find the average of the list of the numbers entered through keyboard

python program to find the largest number from the list of the numbers entered through keyboard

python program to find the sum of n natural numbers

python program to find the sum of first n even numbers

python program to find the sum of first n odd numbers.

python program to generate a list of elements of Fibonacci Series

python program to find simple interest based upon number of years

python program to input any choice and to implement the following

python program to input any number and to print all natural numbers up to given number

python program to input any number and to find sum of all natural numbers up to given number

python program to input any number and to find reverse of that number

python program to input any string and count number of uppercase and lowercase letters

python program to obtain three numbers and print their sum

Python program to obtain length and breath of a rectangle and calculate its area

python program to calculate body mass index of a person

python program to input a number and print its cube

python program to input two number and swap them

python program to input three number and swap 3 numbers

python program to read 3 numbers in 3variables and swap first two variables with the sums of first and second

python program to input a single digit and print a 3 digit number

python program to accept a integer number and find its sum of digit

python program to count the number of digits in given number

python program to find the factorial value of given number

python program to print factor of given number

python program to check given number is composite number or not

python program to find the largest digit of a given number

python program to find the smallest digit of a given number

python program to print table of entered number

python program to calculate the compound interest

python program to find sale price of an item with given price and discount

python program to calculate the sum of odd numbers divisible by 5 from the range 1 to 100

Python Program to Calculate the Area of a Triangle

python program for addition of two times in hour and minute format

python program for addition of two times in hour minute and second format

python program to check number is positive negative or zero

python program to check number is even or odd

python program to check where is profit or loss

python program to check number is buzz number or not

python program to input assets liabilities and capital then check accounting equation means balanced or not

python program to input total debt and total assets and calculate total debt to total assets ratio and check whether major funded by assets or equity

python program to calculate debt to equity check whether it is risky scenario for investor or not

python program to find the difference between greatest and smallest digits presents in the number

python program to print the frequency of digits present in given number

python program to print Floyds triangle

python program to check whether given number is Armstrong or not

python program to find all prime numbers up to given number

python program to convert decimal number to binary

Python program to convert binary to decimal

python program to print quotient

Python program to calculate simple interest

Python program to calculate area and perimeter of a parallelogram

Python program demonstrating working with power operator

Python program of division operator

Python program of modulus

Python program convert dollars in Rupee

Python program to convert kilometers to miles

Python program to convert the distance in feet to inches yards and miles

Python credit card program

Python program to print absolute value of number provided by the user

Python program to check divisibility of a number

Python program to print the largest number

Python program to display menu to calculate area of square or rectangle

Python program to print larger number using swap

Python program to calculate electricity bill

Python program to input three number and print in ascending order

Python program to check character is alphabetic character or not

Python program to print letters of word

Python program to print ASCII code for entered message

Python program to print first ten mersenne numbers

python program to obtain x y z from user and calculate expression

python program that reads a number of seconds and prints it in form mins and seconds

python program to take year as input and check if it is a leap year or not

python program to take two numbers and print if the first number is fully divisible by second number or not

python program to take a 2 digit number and then print the reversed number

python program to take a 3 digit number and then print the reversed number

python program to take two inputs for day month and then calculate which day of the year

python program that asks a user for a number of years and then prints out the number of days hours minutes and seconds

python program that inputs an age and print age after 10 years

python program to find a side of a right angled triangle whose two sides and an angle is given

python program to calculate the radius of a sphere whose area is given

python program to calculate the area of an equilateral triangle

python program to input the radius of a sphere and calculate its volume

python program to calculate amount payable after simple interest

python program to input length of three sides of a triangle Then check if these sides will form a triangle or not

python program to input 3 sides of a triangle and print whether it is an equilateral scalene or isosceles triangle

python program to Print numbers from 11 to N When the number is a multiple of 3 print Tipsy when it is a multiple of 7 print Topsy

python program to input N numbers and then print the second largest number

python program to input list of numbers and find those which are palindromes

python program to place and the most significant digit of number

Python program to print every integer between 1 and n divisible by m Also report whether the number that is divisible by m is even or odd

python program to find the LCM of two input numbers

python program to find GCD of 2 number

python program to check number is perfect number or not

python program to check number is special or not

python program to print first n perfect numbers

Python program using if Elif else statement to find the number of days present in a month

python program to print all buzz numbers between 1 to n

Python program to input 3 numbers and check all are same or not

python program to input 3 numbers from user and check these are unique numbers are not

python program to input 2 integer number and check where they are same of different number

Python function which takes list of integers as input and finds the followings

Python program to print all the prime numbers in the given range

Python program to print the sum of series

python program to input the time in second and convert into hours minute and seconds

python program to obtain the marks in computer of some student and find mean median and mode

Write a Python code to calculate and display the value of Sine 45° and Cosine 30°

python program to input three unequal numbers and display the greatest and the smallest number

python program to accept marks of English math and science and display the appropriate stream allotted to the candidate

python program to calculate income tax based on condition

python program to calculate volume of cuboid cylinder and cone based on user choice

python program to display the first ten terms of the following series 2 5 10 17

python program to find the sum of first ten terms of the series

python program to find the smallest digit of the input number

python program to check whether it is a prime number or not If it is not a prime then display the next number that is prime

python program to accept the Base and Perpendicular and find the Hypotenuse

python program to accept three side of triangle and find its area by using Herons Formula

python program to accept side of Equilateral Triangle and find its area

Python program to check whether dart hit inside board or outside