i = 0
print(f"initial-value: {i}")
while i != 0:
i = i - 1
print(f"while-value: {i}")
else:
i = i + 1
print(f"else-value: {i}")
print(f"final-value: {i}")
initial-value: 0
else-value: 1
final-value: 1
The answer should be A because i is 0 in the first line, which means While won't be execute, then direct goes in to else section. i = i +1 which means i = 0+1, the result is 1.
The value of the i variable when the while loop finishes its execution will be 1. This is because the else clause of the while loop will be executed only if the condition of the loop (i != 0) is not met, which means that the loop will not be executed at all. Since the loop is not executed, the value of i will not be changed, and it will remain 0. However, the else clause will be executed, which contains the statement i = i + 1. This will set the value of i to 1, which is the final value of i when the loop finishes its execution.
is it possible that the answer is D, the variable becomes unavailable? Technically the else statement
is: 0 = 0 + 1, we are saying nothing is equals to something? I know when we run the code and add a print statement the returned value is 1, but the code snipped does not include a print statement, so when the code is run without a print statement, we have to assume the answer is D noting is returned?
This section is not available anymore. Please use the main Exam Page.PCAP Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
jarvisasim
Highly Voted 4 years, 10 months agomajdi_zamiti
Most Recent 2 months ago_vt
4 months, 3 weeks agomegan_mai
9 months ago7cell
1 year, 2 months agopablisluiz1
1 year, 2 months ago86b907f
8 months, 2 weeks agoBere
1 year, 8 months agoValcon_doo_NoviSad
1 year, 9 months agodevadhar
1 year, 10 months agoElsa_Python
1 year, 11 months agoCristianCruz
1 year, 12 months agoCristianCruz
1 year, 12 months agoDrMKG
2 years, 1 month agoAdeshina
2 years, 7 months agoJanpcap123
3 years, 1 month agoJanpcap123
3 years, 1 month agozaxxy
3 years, 1 month ago