Exam PCAP All QuestionsBrowse all questions from this exam
Question 3

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

    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
AvidulamOption: D

The answer is 9.

Dushank

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

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

Correct

eskimolight

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

AdeshinaOption: D

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.

86b907fOption: D

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

DempsdawgOption: B

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

DempsdawgOption: C

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

Irgond07Option: C

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>

BereOption: D

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

KentuckyFriedRiceOption: B

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

mplopezOption: D

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.

DrMKGOption: D

Answer is 9

SadaiyanOption: D

Answer : D : 9

DinshaOption: D

Answer 9

spiderking123Option: D

The answer is 9

BlippenOption: D

9 in the answer

ciccio_benzinaOption: D

it's 9!