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

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

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: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
vlobachevsky
Highly Voted 2 years, 6 months ago
D is correct
upvoted 7 times
mazimir
2 years, 6 months 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 2 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
7 months, 4 weeks ago
Selected Answer: D
The correct answer is D 1 3
upvoted 1 times
...
Janpcap123
8 months ago
The correct and only answer is D: 1 3
upvoted 1 times
...
dicksonpwc
1 year ago
D is correct answer
upvoted 1 times
...
9prayer
1 year, 2 months ago
Selected Answer: D
D is correct
upvoted 1 times
...
Mallie
1 year, 4 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
1 year, 8 months ago
It will give IOError. So answer is D
upvoted 1 times
...
Baldridge
1 year, 11 months ago
D D D D D D D
upvoted 1 times
...
macxsz
2 years ago
Selected Answer: D
answer: D. 1 3
upvoted 3 times
...
MTLE
2 years 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 ago
Ioerror since variable was open with w not r
upvoted 3 times
...
...
Noarmy315
2 years, 4 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 ...