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 106 discussion

Actual exam question from Python Institute's PCAP
Question #: 106
Topic #: 1
[All PCAP Questions]

What is the expected output of the following code if there is no file named non_existing_file inside the working directory?

  • A. 1 2 4
  • B. 1 2 3 4
  • C. 2 4
  • D. 1 3
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

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
vlobachevsky
Highly Voted 3 years, 1 month ago
D is correct
upvoted 7 times
mazimir
3 years, 1 month ago
Agree, D is correct: try: f = open("linije","w") print(1, end="") s = f.readline() print(2, end="") except IOError as error: print(3, end="") else: f.close() print(4,end="")
upvoted 8 times
...
...
Damon54
Most Recent 9 months, 3 weeks ago
The IOError exception is raised by the line s = f.readline() because the file was opened in write mode ('w'), and readline() tries to read from a file opened in write mode, which is not allowed.
upvoted 2 times
...
mplopez
1 year, 2 months ago
Selected Answer: D
The correct answer is D 1 3
upvoted 1 times
...
Janpcap123
1 year, 2 months ago
The correct and only answer is D: 1 3
upvoted 1 times
...
dicksonpwc
1 year, 7 months ago
D is correct answer
upvoted 1 times
...
9prayer
1 year, 9 months ago
Selected Answer: D
D is correct
upvoted 1 times
...
Mallie
1 year, 11 months ago
Selected Answer: D
How can the 'Suggested answer' C ever be correct? That doesn't make any sense. Answer is D
upvoted 1 times
...
Jnanada
2 years, 3 months ago
It will give IOError. So answer is D
upvoted 1 times
...
Baldridge
2 years, 6 months ago
D D D D D D D
upvoted 1 times
...
macxsz
2 years, 6 months ago
Selected Answer: D
answer: D. 1 3
upvoted 3 times
...
MTLE
2 years, 7 months ago
There is no IO error as w creates a new file. The only operation which raises IO error is either r or r+
upvoted 2 times
macxsz
2 years, 7 months ago
Ioerror since variable was open with w not r
upvoted 3 times
...
...
Noarmy315
2 years, 11 months ago
D s = f.readline() --> io.UnsupportedOperation: not readable
upvoted 2 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 ...