1. What is the value of x
after the following nested for loop completes its execution
x = 0
for i in range(10):
for j in range(-1, -10, -1):
x += 1
print(x)
a. 99
b. 90
c. 100
2. What is the output of the following loop
for l in 'Jhon':
if l == 'o':
pass
print(l, end=", ")
a. J, h, n,
b. J, h, o, n,
3. Given the nested if-else
below, what will be the value x
when the code executed successfully
x = 0
a = 5
b = 5
if a > 0:
if b < 0:
x = x + 5
elif a > 5:
x = x + 4
else:
x = x + 3
else:
x = x + 2
print(x)
a. 0
b. 4
c. 2
d. 3
4. What is the output of the following for loop and range()
function
for num in range(-2,-5,-1):
print(num, end=", ")
a. -2, -1, -3, -4
b. -2, -1, 0, 1, 2, 3,
c. -2, -1, 0
d. -2, -3, -4,
5. 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)
a. 20
b. 21
c. 10
d. 30
6. Given the nested if-else
structure below, what will be the value of x
after code execution completes
x = 0
a = 0
b = -5
if a > 0:
if b < 0:
x = x + 5
elif a > 5:
x = x + 4
else:
x = x + 3
else:
x = x + 2
print(x)
a. 2
b. 0
c. 3
d. 4
7. What is the value of x
x = 0
while (x < 100):
x+=2
print(x)
a. 101
b. 99
c. None of the above, this is an infinite loop
d. 100
8. What is the output of the following range()
function
for num in range(2,-5,-1):
print(num, end=", ")
a. 2, 1, 0
b. 2, 1, 0, -1, -2, -3, -4, -5
c. 2, 1, 0, -1, -2, -3, -4