0% found this document useful (0 votes)
17 views2 pages

Exp4

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

Exp4

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

Shri Swami Vivekanand Shikshan Santha’s

Vivekanand College, Kolhapur


(Empowered Autonomous)
DEPARTMENT OF MATHEMATICS
Name of the Student: Date :

Experiement No : 4 Remark

Python For Loops :- A for loop is used for iterating over a sequence (that is either a list, a tuple, a
dictionary, a set, or a string). This is less like the for keyword in other programming languages, and works
more like an iterator method as found in other object-orientated programming languages.
With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.
for i in range ( start , stop , step )

Program (Spilt the string) Output


x = ' ABCD ' A
for i in x : B
print ( i ) C
D
Program (Write word n times ) Output
for i in range ( 1 , 6 , 1 ) : Hello
print ( ‘Hello’ ) Hello
Hello
Hello
Hello
Program (Write a table of n ) Output
n = int ( input ( ' Enter a number ' ) ) 3
for i in range ( 1 , 11 , 1 ) : 6
print ( n * i ) 9

30

Nested Loops :- A nested loop is a loop inside a loop. The "inner loop" will be executed one time for each
iteration of the "outer loop":

Program (Write a cooradinate sets ) Output


colour = ["red","blue","black"] red apple
fruits = ["apple","banana","cherry"] red banana
for x in colours: red cherry
for y in fruits: blue apple
print(x, y) blue banana
blue cherry
black apple
black banana
black cherry
Program (Write a cooradinate sets) Output
for x in range(1,4,1): 11
for y in range(1,3,1): 12
print(x, y) 21
22
31
32

The while Loop :- With the while loop we can execute a set of statements as long as a condition is true.
Program (Write a number 1 to 5 ) Output
i=1 1
while i < 6: 2
print(i) 3
i += 1 4
5

You might also like