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

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
TheFivePips
4 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
6 months, 2 weeks ago
Selected Answer: BD
B and D.
upvoted 2 times
...
Senthorus
9 months, 3 weeks 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
9 months, 3 weeks ago
oops wrong link https://www.w3schools.com/python/ref_func_open.asp
upvoted 1 times
...
...
Ello2023
10 months, 2 weeks 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
2 months, 2 weeks ago
but str is not a string
upvoted 1 times
...
...
EltonAuguston
11 months, 1 week 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, 2 months ago
Selected Answer: AD
For me A is more correct than B
upvoted 4 times
...
agus007
1 year, 5 months 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, 1 month 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
1 year, 8 months ago
Answer should be B and D
upvoted 1 times
...
rmehmood
1 year, 8 months ago
A is not correct, as str is not a string, its a file object
upvoted 1 times
...
palagus
1 year, 11 months ago
Selected Answer: AD
Both statements are true. Statement B could be true or not regarding its content.
upvoted 1 times
...
666_m
1 year, 11 months ago
Correct answers are A&D
upvoted 1 times
...
macxsz
1 year, 11 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
1 year, 12 months ago
Selected Answer: BD
The correct answers are: B and D.
upvoted 2 times
...
rocky48
2 years, 1 month 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
2 years, 5 months 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
2 years, 6 months 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
2 years, 7 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 ...