PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 3


What will the value of the i variable be when the following loop finishes its execution?

Show Answer
Correct Answer: D

In the given loop, 'range(10)' generates a sequence of numbers from 0 to 9. The variable 'i' iterates over these values. When the loop completes, the last value assigned to 'i' is 9. Thus, the value of the 'i' variable when the loop finishes its execution is 9.

Discussion

17 comments
Sign in to comment
AvidulamOption: D
Mar 10, 2020

The answer is 9.

Dushank
Jan 18, 2021

Just try to print the value of i after the loop, you would get 9 as result. <code> for i in range(10): pass print(i) </code>

HarrySoniOption: D
Apr 3, 2020

9 is the Answer. Pass only means there are no statements to execute it does not means the variable is unavailable. Try a Print statemnt Print(i) after the For Loop and there is your result.

imsaad
Aug 7, 2020

Correct

AdeshinaOption: D
Dec 11, 2022

D is the right answer. The value of the i variable when the for loop finishes its execution will be 9. This is because the range(10) function generates a sequence of numbers from 0 to 9, and the for loop will iterate over this sequence, with the variable i taking on each value in turn. When the for loop reaches the end of the sequence, it will stop, and the value of i at that point will be 9.

eskimolight
Nov 23, 2023

Can someone confirm if this exam code is PCAP-31-03 ?

ciccio_benzinaOption: D
Sep 4, 2022

it's 9!

BlippenOption: D
Jan 24, 2023

9 in the answer

spiderking123Option: D
Mar 5, 2023

The answer is 9

DinshaOption: D
Mar 8, 2023

Answer 9

SadaiyanOption: D
May 8, 2023

Answer : D : 9

DrMKGOption: D
May 24, 2023

Answer is 9

mplopezOption: D
Jul 22, 2023

The for loop start to count from 0 and de range of members that must to iterate are 10 loops, that says the loop begins in 0 and finish in 9.

KentuckyFriedRiceOption: B
Sep 8, 2023

The answer is B because i is an interation variable. Once the loop has finished execution, it is no longer accessible.

BereOption: D
Oct 26, 2023

for i in range(10): print(f"for-i: {i}") pass print(f"final-i: {i}") for-i: 0 for-i: 1 for-i: 2 for-i: 3 for-i: 4 for-i: 5 for-i: 6 for-i: 7 for-i: 8 for-i: 9 final-i: 9

Irgond07Option: C
Jan 29, 2024

C:\Python_Local\Python_CMD\PCAP>more pcep1.py for i in range(10): pass print(i) C:\Python_Local\Python_CMD\PCAP>python pcep1.py 0 1 2 3 4 5 6 7 8 9 C:\Python_Local\Python_CMD\PCAP>

DempsdawgOption: C
Mar 21, 2024

for i in range(10): pass Sub pass for print(i): 0 1 2 3 4 5 6 7 8 9

DempsdawgOption: B
Mar 21, 2024

for i in range(10): pass #This pass will make it C because there is NO print function

86b907fOption: D
Jun 10, 2024

I'm seeing answer B, C and D in the comments ... strange ?