Mujtaba Baig Lab 6
Mujtaba Baig Lab 6
LAB # 06
NESTED STATEMENTS,
BREAK AND CONTINUE STATEMENTS
OBJECTIVE
Working on nested statements and control loop iteration using break and continue.
EXERCISE
A. Point out the errors, if any, and paste the output in the following Python
programs.
1. Code
prompt = "\nPlease enter the name of a city you have visited:"
prompt+="\n(Enter 'quit' when you are finished.)"
while True:
city = str(input(prompt))
if city == quit:
break;
else:
print("I'd love to go to " , city.title() , "!")
Error:
Output
Source Code:
Corrrection:
MUJTABA BAIGB FALL-2022-BSE-106
2. Code
if x>2:
if y>2:
z=x+y
print(“z is”, y)
else:
print(“x is”, x)
Output
Error:
Source code:
Correction:
3. Code
balance = int(input("enter yourbalance1:"))
while true:
if balance <=9000:
continue;
balance = balance+999.99
MUJTABA BAIGB FALL-2022-BSE-106
Output
Error:
Source code:
Correction:
1. Code
Output
i = 10
if (i==10):
#First if statement
if (i < 15):
print ("i is smaller than 15")
# Nested - if statement
# Will only be executed if statement above
# it is true
if (i < 12):
print ("i is smaller than 12 too")
else:
print ("i is greater than 15")
MUJTABA BAIGB FALL-2022-BSE-106
2. Code
i = 1 i = 1
j = 2 j = 2
k = 3 k = 3
if i > j: if i > j:
if i > k: if i> k:
print('A') print('A')
else: else:
print('B') print('B')
Output
3. Code
# nested for loops
for i in range(0, 5):
for j in range(i):
print(i, end=' ')
print()
Output
1. Write a program to add first seven terms twice of the following series:
Source code:
MUJTABA BAIGB FALL-2022-BSE-106
Output:
Output: