Conditional Formatting _While And For Loops — Part 2 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Conditional Formatting _While And For Loops — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? for i in range(2.0): print(i)
Correct Answer: Option C — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code? for i in range(2.0): print(i)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? for i in range(int(2.0)): print(i)
Correct Answer: Option B — 0 1
Detailed Academic Explanation:
0 1 is the correct answer to “What will be the output of the following Python code? for i in range(int(2.0)): print(i)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? for i in ''.join(reversed(list('abcd'))): print (i)
Correct Answer: Option B — d c b a
Detailed Academic Explanation:
d c b a is the correct answer to “What will be the output of the following Python code snippet? for i in ''.join(reversed(list('abcd'))): print (i)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? x = 2 for i in range(x): x += 1 print (x)
Correct Answer: Option C — 3 4
Detailed Academic Explanation:
3 4 is the correct answer to “What will be the output of the following Python code snippet? x = 2 for i in range(x): x += 1 print (x)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? for i in range(float('inf')): print (i)
Correct Answer: Option D — none of the mentioned
Detailed Academic Explanation:
none of the mentioned is the correct answer to “What will be the output of the following Python code? for i in range(float('inf')): print (i)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? for i in range(int(float('inf'))): print (i)
Correct Answer: Option D — none of the mentioned
Detailed Academic Explanation:
none of the mentioned is the correct answer to “What will be the output of the following Python code? for i in range(int(float('inf'))): print (i)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? x = 2 for i in range(x): x -= 2 print (x)
Correct Answer: Option B — 0 -2
Detailed Academic Explanation:
0 -2 is the correct answer to “What will be the output of the following Python code snippet? x = 2 for i in range(x): x -= 2 print (x)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = 123 for i in x: print(i)
Correct Answer: Option C — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code? x = 123 for i in x: print(i)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? d = {0, 1, 2} for x in d: print(x)
Correct Answer: Option A — 0 1 2
Detailed Academic Explanation:
0 1 2 is the correct answer to “What will be the output of the following Python code? d = {0, 1, 2} for x in d: print(x)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? d = {0, 1, 2} for x in d.values(): print(x)
Correct Answer: Option C — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code? d = {0, 1, 2} for x in d.values(): print(x)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for i in d: print(i)
Correct Answer: Option A — 0 1 2
Detailed Academic Explanation:
0 1 2 is the correct answer to “What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for i in d: print(i)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x, y in d.items(): print(x, y)
Correct Answer: Option C — 0 a 1 b 2 c
Detailed Academic Explanation:
0 a 1 b 2 c is the correct answer to “What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x, y in d.items(): print(x, y)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? d = {0, 1, 2} for x in d: print(d.add(x))
Correct Answer: Option C — None None None
Detailed Academic Explanation:
None None None is the correct answer to “What will be the output of the following Python code? d = {0, 1, 2} for x in d: print(d.add(x))”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.keys(): print(d[x])
Correct Answer: Option B — a b c
Detailed Academic Explanation:
a b c is the correct answer to “What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.keys(): print(d[x])”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.values(): print(x)
Correct Answer: Option B — a b c
Detailed Academic Explanation:
a b c is the correct answer to “What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.values(): print(x)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.values(): print(d[x])
Correct Answer: Option D — none of the mentioned
Detailed Academic Explanation:
none of the mentioned is the correct answer to “What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.values(): print(d[x])”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x, y in d: print(x, y)
Correct Answer: Option D — none of the mentioned
Detailed Academic Explanation:
none of the mentioned is the correct answer to “What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x, y in d: print(x, y)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? for i in range(0): print(i)
Correct Answer: Option B — no output
Detailed Academic Explanation:
no output is the correct answer to “What will be the output of the following Python code? for i in range(0): print(i)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = 'abcd' for i in range(x): print(i)
Correct Answer: Option C — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code? x = 'abcd' for i in range(x): print(i)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): print(x) x = 'a'
Correct Answer: Option D — none of the mentioned
Detailed Academic Explanation:
none of the mentioned is the correct answer to “What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): print(x) x = 'a'”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): i.upper() print (x)
Correct Answer: Option C — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): i.upper() print (x)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): x[i].upper() print (x)
Correct Answer: Option A — abcd
Detailed Academic Explanation:
abcd is the correct answer to “What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): x[i].upper() print (x)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): i[x].upper() print (x)
Correct Answer: Option C — none of the mentioned
Detailed Academic Explanation:
none of the mentioned is the correct answer to “What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): i[x].upper() print (x)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = 'abcd' for i in range(len(x)): print(i.upper())
Correct Answer: Option C — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code? x = 'abcd' for i in range(len(x)): print(i.upper())”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = 'abcd' for i in x: print(i) x.upper()
Correct Answer: Option B — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code? x = 'abcd' for i in x: print(i) x.upper()”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): x = 'a' print(x)
Correct Answer: Option C — a a a a
Detailed Academic Explanation:
a a a a is the correct answer to “What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): x = 'a' print(x)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = "abcdef" while i in x: print(i, end=" ")
Correct Answer: Option D — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code? x = "abcdef" while i in x: print(i, end=" ")”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = "abcdef" i = "a" while i in x: x = x[1:] print(i, end = " ")
Correct Answer: Option B — a
Detailed Academic Explanation:
a is the correct answer to “What will be the output of the following Python code? x = "abcdef" i = "a" while i in x: x = x[1:] print(i, end = " ")”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = "abcdef" i = "a" while i in x[1:]: print(i, end = " ")
Correct Answer: Option C — no output
Detailed Academic Explanation:
no output is the correct answer to “What will be the output of the following Python code? x = "abcdef" i = "a" while i in x[1:]: print(i, end = " ")”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = "abcdef" i = "i" while i in x: print(i, end=" ")
Correct Answer: Option A — no output
Detailed Academic Explanation:
no output is the correct answer to “What will be the output of the following Python code? x = "abcdef" i = "i" while i in x: print(i, end=" ")”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? i = 0 while i < 3: print(i) i += 1 else: print(0)
Correct Answer: Option B — 0 1 2 0
Detailed Academic Explanation:
0 1 2 0 is the correct answer to “What will be the output of the following Python code? i = 0 while i < 3: print(i) i += 1 else: print(0)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0)
Correct Answer: Option B — 0 1 2
Detailed Academic Explanation:
0 1 2 is the correct answer to “What will be the output of the following Python code? i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = "abcdef" i = "a" while i in x: print(i, end = " ")
Correct Answer: Option C — a a a a a a ...
Detailed Academic Explanation:
a a a a a a ... is the correct answer to “What will be the output of the following Python code? x = "abcdef" i = "a" while i in x: print(i, end = " ")”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? i = 2 while True: if i%3 == 0: break print(i) i += 2
Correct Answer: Option B — 2 4
Detailed Academic Explanation:
2 4 is the correct answer to “What will be the output of the following Python code? i = 2 while True: if i%3 == 0: break print(i) i += 2”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? i = 1 while True: if i%2 == 0: break print(i) i += 2
Correct Answer: Option D — 1 3 5 7 9 11 ...
Detailed Academic Explanation:
1 3 5 7 9 11 ... is the correct answer to “What will be the output of the following Python code? i = 1 while True: if i%2 == 0: break print(i) i += 2”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = ['ab', 'cd'] for i in x: x.append(i.upper()) print(x)
Correct Answer: Option C — none of the mentioned
Detailed Academic Explanation:
none of the mentioned is the correct answer to “What will be the output of the following Python code? x = ['ab', 'cd'] for i in x: x.append(i.upper()) print(x)”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? i = 5 while True: if i%0O9 == 0: break print(i) i += 1
Correct Answer: Option D — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code? i = 5 while True: if i%0O9 == 0: break print(i) i += 1”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? True = False while True: print(True) break
Correct Answer: Option D — none of the mentioned
Detailed Academic Explanation:
none of the mentioned is the correct answer to “What will be the output of the following Python code? True = False while True: print(True) break”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? i = 1 while False: if i%2 == 0: break print(i) i += 2
Correct Answer: Option D — none of the mentioned
Detailed Academic Explanation:
none of the mentioned is the correct answer to “What will be the output of the following Python code? i = 1 while False: if i%2 == 0: break print(i) i += 2”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? i = 5 while True: if i%0O11 == 0: break print(i) i += 1
Correct Answer: Option B — 5 6 7 8
Detailed Academic Explanation:
5 6 7 8 is the correct answer to “What will be the output of the following Python code? i = 5 while True: if i%0O11 == 0: break print(i) i += 1”. This question is standard in competitive examination syllabi for Conditional Formatting _While And For Loops.
💡Key Conceptual Anchor:Conditional Formatting _While And For Loops
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.