Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Python Institute Exam PCAP-31-03 Topic 4 Question 65 Discussion

Actual exam question for Python Institute's PCAP-31-03 exam
Question #: 65
Topic #: 4
[All PCAP-31-03 Questions]

What is the expected output of the following code if the file named existing_text_file is a non-zero length text file located inside the working directory?

Show Suggested Answer Hide Answer
Suggested Answer: A, D

Contribute your Thoughts:

Curtis
5 days ago
Wow, this question is a real head-scratcher! I'm going to go with option A and hope the file doesn't have any blank lines. If it does, I might have to resort to my trusty 8-ball for the answer.
upvoted 0 times
...
Refugia
14 days ago
Option D is tempting, but I don't think that's correct. The code is not specifically getting the last line, it's just getting the length of the first line.
upvoted 0 times
...
Leana
17 days ago
Haha, well, if the file is empty, the output should be -1, right? That's what option B is saying. But I guess that's not the case here since the question says the file is non-zero length.
upvoted 0 times
...
Veronika
18 days ago
I think the correct answer is C. The code is iterating through the lines in the file, so the output should be the number of lines contained inside the file.
upvoted 0 times
...
Nan
19 days ago
The expected output is the length of the first line from the file. This is because the code is using the `len()` function to get the length of the first line read from the file.
upvoted 0 times
...
Titus
20 days ago
But the code is reading the file line by line, so it makes sense that the output would be the number of lines, not the length of the last line.
upvoted 0 times
...
Rocco
22 days ago
I disagree, I believe the answer is D) the length of the last line from the file.
upvoted 0 times
...
Titus
27 days ago
I think the answer is C) the number of lines contained inside the file.
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77