Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCAP All Questions

View all questions & answers for the PCAP exam

Exam PCAP topic 1 question 107 discussion

Actual exam question from Python Institute's PCAP
Question #: 107
Topic #: 1
[All PCAP 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?

  • A. the length of the first line from the file
  • B. -1
  • C. the number of lines contained inside the file
  • D. the length of the last line from the file
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Jos015
1 year ago
Selected Answer: B
try: f = open('file.txt','w') d = f.readline() print(len(d)) f.close() except IOError: print(-1) Read with 'r' try: f = open('file.txt','r') d = f.readline() print(len(d)) f.close() except IOError: print(-1)
upvoted 1 times
...
macxsz
2 years, 6 months ago
Selected Answer: B
answer: B. -1
upvoted 3 times
...
Mokel
2 years, 7 months ago
Shouldn't it be (c)?
upvoted 2 times
macxsz
2 years, 7 months ago
It cant be read because it was open with w
upvoted 4 times
...
...
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.

SaveCancel
Loading ...