1.
Which of the following is not used as loop in Python?
2.
What will be the output of given Python code?
n=7
c=0
while(n):
Β Β if(n>5):
Β Β Β Β c=c+n-1
Β Β Β Β n=n-1
Β Β else:
Β Β Β Β break
print(n)
print(c)
Β
3.
Which of the following Python code will give different output from the others?
4.
What keyword would you use to add an alternative condition to an if statement?
5.
Can we write if/else into one line in python?
6.
What will be output of this expression:
'p' + 'q' if '12'.isdigit() else 'r' + 's'
7.
What will be the output of the following code?
list1 = [3 , 2 , 5 , 6 , 0 , 7, 9]
sum = 0
sum1 = 0
for elem in list1:
Β Β if (elem % 2 == 0):
Β Β Β Β sum = sum + elem
Β Β Β Β continue
Β Β if (elem % 3 == 0):
Β Β Β Β sum1 = sum1 + elem
Β
print(sum , end=" ")
print(sum1)
8.
What is the value of the var after the for loop completes its execution?
var = 10
for i in range(10):
Β Β for j in range(2, 10, 1):
Β Β Β Β if var % 2 == 0:
Β Β Β Β Β Β continue
Β Β Β Β Β Β var += 1
Β Β var+=1
else:
Β Β var+=1
print(var)
9.
What is the output of the following nested loop ?
numbers = [10, 20]
items = ["Chair", "Table"]
Β
for x in numbers:
Β for y in items:
Β Β print(x, y)
10.
Which statement will check if a is equal to b?