Completed
Mixed: conditionals + loops
Questions From This Challenge
Q1mcq1 mark
What is the output of the following code?
n = 5
fact = 1
i = 1
while i <= n:
fact = fact * i
i += 1
print(fact)
120 ✓
24
60
720
Q2mcq1 mark
What is the output of the following code?
total = 0
for i in range(1, 11):
if i % 2 == 0:
total += i
if total > 25:
print("High")
else:
print("Low")
High ✓
Low
Error
30
Q3mcq1 mark
What is the output of the following code?
n = 9
count = 0
for i in range(1, n + 1):
if n % i == 0:
count += 1
if count == 2:
print("Prime")
else:
print("NotPrime")
Prime
NotPrime ✓
Error
9
Q4mcq1 mark
What is the output of the following code?
n = 1
while True:
if n % 3 == 0 and n % 4 == 0:
break
n += 1
print(n)
12 ✓
6
24
4
Q5mcq1 mark
What is the output of the following code?
target = 7
count = 0
for i in range(1, 6):
for j in range(1, 6):
if i + j == target:
count += 1
print(count)
4 ✓
3
5
6
Q6output1 mark
What is the output?
n = 1
total = 0
while n <= 50:
total += n
if total > 30:
break
n += 1
print(total)
Correct output:
36Q7output1 mark
What is the output?
pos = 0
neg = 0
zero = 0
nums_total = 0
for i in range(-3, 4):
nums_total += 1
if i > 0:
pos += 1
elif i < 0:
neg += 1
else:
zero += 1
print(pos)
print(neg)
print(zero)
Correct output:
3
3
1Q8output1 mark
What is the output?
for i in range(1, 4):
row_sum = 0
for j in range(1, i + 1):
row_sum += j
print(row_sum)
Correct output:
1
3
6Q9output1 mark
What is the output?
n = 6
i = 1
fact = 1
while i <= n:
fact = fact * i
if fact > 100:
break
i += 1
print(fact)
Correct output:
120Q10output1 mark
What is the output?
total = 0
for i in range(1, 4):
for j in range(1, 4):
if i == j:
continue
total += i * j
print(total)
Correct output:
22Q11output1 mark
What is the output?
for i in range(1, 11):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
Correct output:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
BuzzQ12output1 mark
What is the output?
total = 0
for i in range(1, 6):
for j in range(1, i + 1):
total += j
if total > 15:
break
print(total)
Correct output:
20Q13output1 mark
What is the output?
num = 2
product = 1
count = 0
while count < 10:
product = product * num
count += 1
if product > 50:
break
print(product)
print(count)
Correct output:
64
6Q14output1 mark
What is the output?
total = 0
for i in range(1, 7):
for j in range(1, 7):
if i == j:
continue
if i * j % 2 == 0:
continue
total += i * j
if total > 20:
break
print(total)
Correct output:
31Q15output1 mark
What is the output?
n = 99
while n > 0:
if n % 6 == 0 and n % 8 == 0:
break
n -= 1
print(n)
Correct output:
96