0% found this document useful (0 votes)
2 views6 pages

Python2

Uploaded by

annoyingraptor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Python2

Uploaded by

annoyingraptor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Shyamsir Python Language 78 74 39 11 91

Loop
The for loop executes a block of statements a specified number of times.

It is the most commonly and most popular loop used in any programming language.

Syntax#

for i in range(1,n+1):

Logic….

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91
for i in range(1,n+1): for i in range(1,n+1,20): for i in range(n,0,-1):

Logic…. Logic…. Logic….

The range() function returns a sequence of numbers, starting from 0 by default,


and increments by 1 (by default), and ends at a specified number.

List1=[“a”,”t”,”m”,”k”]
for x in List1:

Logic….

While

i=1 i=10 i=1

while i<=n: while i>=1: while i<=n:

print(….. print(….. print(…..


i=i+1 i=i-1 i=i+1

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

For Loops programs:

1. Print your name 20 times

(Hint:
for i in range(1,21):
.....

2. 1 to 10

(Hint:
for i in range(1,11):
.....

3. 1 to N

(Hint:
for i in range(1,n+1):
.....

4. Write a program to print “4 is square of 2” from 1 to N.

(Hint:
for i in range(1,n+1):
print(i*i," is square of

5. Write a program to print sum of all numbers from given range of integer.

(Hint:
for i in range(1,n+1):
s=s+

6. Print data in given format


1 is odd
2 is even
3 is odd

(Hint:
for i in range(1,n+1):
if i%2 ==0:

6. Table

(Hint:
Enter no => 7
for i in range(1,11):
print(no," X "

7. Print only divisible by 7 upto N

(Hint:

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91
Enter no => 30
for i in range(1,n+1):
if i % ?

8. Print only divisible by K upto N and print Sum and Count

(Hint:
Enter no => 30
Enter divisable by => 7
for i in range(1,n+1):
if i % ?

9. Print Sum of odd / even and Count of odd / even upto N

(Hint:
Enter no => 30
Enter divisable by => 7
for i in range(1,n+1):
if i % ?

10. 1+2+3+4+5 , Enter limit , display series and sum


Sum = 15

(Hint:
s=0
Enter no => 5
for i in range(1,n+1):
print
s=
print

11. 1+4+9+16+25, Enter limit , display series and sum


Sum = 55
(Hint:
s=0
Enter no => 5
for i in range(1,n+1):
print
s=
print

12. 1-4+9-16+25….., Enter limit , display series and sum


Sum = 15
(Hint:
s=0
Enter no => 5
for i in range(1,n+1):
if..
print

13. 1+3+5+7……..+n ,Enter limit , display series and sum


Sum = ..
(Hint:
s=0
Enter no => 10

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91
for i in range(1,n+1):
if..
print

14. 1/1+1/2+1/3+1/4……….Enter limit and display series only


(Hint:
Enter no => 10
for i in range(1,n+1):
print

15. Find out Factorial ,Enter any number and display series and factorial of it
(Hint:
f=1
Enter no => 5
for i in range(1,n+1):
print
f
print

16. Enter no and check whether that no is prime or not (The number is divisable by
itself and 1)
(Hint:
Enter no => 13
x=1
for i in range(1,n):
if..
if x==

While Loop
1. 1 to N

(Hint:
i=1
while i<=n:
print(
i=i+1

2. Print Table

(Hint:
i=1
while i<=11:
print(
i=i+1

3. 1 to N , 1 is odd , 2 is even , 3 is odd , 4 is even , n…..

(Hint:
i=1
while i<=n:
if..
else
i=i+1

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

4. Factorial 5 X 4 X 3 X 2 X 1 , 120

(Hint:
i=n
f=1
while i>=1:

i=i-1

www.Shyamsir.com

You might also like