(1) Develop programs to understand the control structures of python
1) While Loop,
2) For in Loop,
3) Continue Statement,
4) Break Statement
2) For in Loop,
4) Break Statement
Program Code:
1) While Loop:
1) While Loop:
print("Lab-1-While Loop")
# prints Hello 3 Times
count = 0
while (count < 3):
count = count+1
print("Hello Python.")
count = 0
while (count < 3):
count = count+1
print("Hello Python.")
2) For in Loop:
# For in Loop
print("\nString Iteration")
s = "Python"
for i in s :
print(i)
print("List Iteration")
l = ["A", "for", "Apple"]
for i in l:
print(i)
Output:For in Loop:

# For in Loop
print("\nString Iteration")
s = "Python"
for i in s :
print(i)
print("List Iteration")
l = ["A", "for", "Apple"]
for i in l:
print(i)
Output:For in Loop:
3) Continue Statement:
# Prints all letters except 'e' and 's'
for letter in 'Hello Python.':
if letter == 'e' or letter == 's':
continue
print ("Current Letter :", letter )
var = 10
Output:Continue Statement:

4) Break Statement:
for letter in 'helloworld':
# break the loop as soon it sees 'e'
# or 's'
if letter == 'e' or letter == 's':
break
print ("Current Letter :", letter)
Output:Break Statement:
# Prints all letters except 'e' and 's'
for letter in 'Hello Python.':
if letter == 'e' or letter == 's':
continue
print ("Current Letter :", letter )
var = 10
Output:Continue Statement:
4) Break Statement:
for letter in 'helloworld':
# break the loop as soon it sees 'e'
# or 's'
if letter == 'e' or letter == 's':
break
print ("Current Letter :", letter)
No comments:
Post a Comment