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

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

What can you deduce from the following statement? (Choose two.)

  • A. str is a string read in from the file named file.txt
  • B. a newline character translation will be performed during the reads
  • C. if file. txt does not exist, it will be created
  • D. the opened file cannot be written with the use of the str variable
Show Suggested Answer Hide Answer
Suggested Answer: BD 🗳️

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
TheFivePips
11 months, 3 weeks ago
Selected Answer: BD
A. str is a string read in from the file named file.txt. The variable name str might be misleading, but in this context, it represents a file object, not a string. The open() function is used to open a file, not to read the content into a string. So, option A is not correct. B. A newline character translation will be performed during the reads. The mode "rt" stands for "read text." In text mode, newline characters are automatically translated to the appropriate line ending for the platform (e.g., \n on Unix-based systems, \r\n on Windows). So, option B is correct. C. If file.txt does not exist, it will be created. The mode "rt" opens the file in read text mode. If the file does not exist, it will raise a FileNotFoundError. So, option C is not correct. D. The opened file cannot be written with the use of the str variable. The file is opened in read text mode, which means you can read from it, but attempting to write to it would result in an error. So, option D is correct. Therefore, the correct deductions are B and D.
upvoted 4 times
...
Valcon_doo_NoviSad
1 year, 1 month ago
Selected Answer: BD
B and D.
upvoted 2 times
...
Senthorus
1 year, 4 months ago
Selected Answer: BD
It's BD because open return a file object not a string. https://github.com/sundowndev/phoneinfoga
upvoted 2 times
Senthorus
1 year, 4 months ago
oops wrong link https://www.w3schools.com/python/ref_func_open.asp
upvoted 1 times
...
...
Ello2023
1 year, 5 months ago
Selected Answer: AD
'rt' means read 'wt' means write In this piece of code we are opening a file with the name file.txt which is readable. str = open ('file.txt', 'rt')
upvoted 1 times
Oracleist
9 months, 3 weeks ago
but str is not a string
upvoted 1 times
...
...
EltonAuguston
1 year, 6 months ago
this is why A is incorrect : The variable str does not necessarily represent a string read from the file. It represents the file object returned by the open() function. To read the contents of the file into a string, you would need to use additional code like str_contents = str.read(). >>> B & D (correct)
upvoted 2 times
...
Netspud
1 year, 9 months ago
Selected Answer: AD
For me A is more correct than B
upvoted 4 times
...
agus007
2 years ago
A. may be correct if they change from 'string' to 'stream' there may be a typo. B. Is correct, only if the we are running over windows. With Unix-like OS there is no translation. And C is correct.
upvoted 3 times
Rizos
1 year, 8 months ago
How is C correct? I tried this, and if the file does not exist, it will say: "No such file or directory". So that one is incorrect.
upvoted 1 times
...
...
Jnanada
2 years, 3 months ago
Answer should be B and D
upvoted 1 times
...
rmehmood
2 years, 3 months ago
A is not correct, as str is not a string, its a file object
upvoted 1 times
...
palagus
2 years, 6 months ago
Selected Answer: AD
Both statements are true. Statement B could be true or not regarding its content.
upvoted 1 times
...
666_m
2 years, 6 months ago
Correct answers are A&D
upvoted 1 times
...
macxsz
2 years, 6 months ago
Selected Answer: BD
B. a newline character translation will be performed during the reads D. the opened file cannot be written with the use of the str variable
upvoted 2 times
...
hibana2077
2 years, 7 months ago
Selected Answer: BD
The correct answers are: B and D.
upvoted 2 times
...
rocky48
2 years, 8 months ago
Selected Answer: BD
B. a newline character translation will be performed during the reads D. the opened file cannot be written with the use of the str variable
upvoted 1 times
...
DKM
3 years ago
b. a newline character translation will be performed during the reads d. the opened file cannot be written with the use of the str variable
upvoted 2 times
...
rbishun
3 years, 1 month ago
The correct answers are: B and D. "rt" means read file as text (which is the default anyway). More info here: https://docs.python.org/3/library/functions.html#open
upvoted 3 times
...
Emirates34
3 years, 2 months ago
I believe the given answer is incorrect. A - str is a file handle and does not contain the file contents.
upvoted 1 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 ...