Question

In: Computer Science

This is a python 3.0 question, there are either 1 or 2 answers for each sub-question....

This is a python 3.0 question, there are either 1 or 2 answers for each sub-question.

Part i) Which of the following statements regarding the opening modes of a file are true?

Select one or more:

a. When you open a file for writing, if the file does not exist, a new file is created.

b. When you open a file for writing, if the file exists, the existing file is overwritten with the new file.

c. When you open a file for writing, if the file does not exist, an error occurs.

d. When you open a file for reading, if the file does not exist, the program will open an empty file.

e. When you open a file for reading, if the file does not exist, an error occurs.

Part ii) What is the data type of the value returned by the read() or readline() methods of a file object, assuming that file object is associated to a pure text file?

Select one or more:

a. int

b. It depends on the data type of the values stored in the file.

c. list

d. str

Part iii) Which of the following methods of a file object reads the entire file into a single string?

Select one or more:

a. readline() if and only if there are no newline characters in the file

b. readlines()

c. read_file_to_str()

d. read()

Solutions

Expert Solution

Answer

Here is your answer, if you have any doubt please comment, i am here to help you.

1) Answer : A,B ,E

we can handle file in python using open() function.The open() function takes two parameters; filename, and mode.


#mode specified in double quotes.

"r" - Read - Default value. Opens a file for reading, error if the file does not exist
"w" - Write - Opens a file for writing and creates the file if it does not exist
"a" - Append - Opens a file for appending and creates the file if it does not exist
"x" - Create - Creates the specified file and returns an error if the file exists

2) readlines():method returns a list containing each line in the file as a list item.

     read()           :this method will read entire file as str.

example:

So answer is C and D.

3) Answer , A and D,

readline() if and only if there are no newline characters in the file. Only take one line of the file and make it as str.

read() also take entire take as str.

readlines() will print list of strings

If you have any doubt please comment

Thanks in advance


Related Solutions

Question 1 0.11 M NaCN; Kf for Ag(CN)−2 is 3.0×1020. Express your answers using two significant...
Question 1 0.11 M NaCN; Kf for Ag(CN)−2 is 3.0×1020. Express your answers using two significant figures. Question 2 What is ΔG for the formation of solid uranium hexafluoride from uranium and fluorine at 25∘C when the partial pressure of F2 is 0.077 atm ? The standard free energy of formation of UF6(s) is -2068 kJ/mol. U(s)+3F2(g)→UF6(s) Express your answer to four significant figures and include the appropriate units. Question 3 Calculate the equilibrium constant Kp at 25 ∘C for...
Answer the following four sub-questions. Each sub-question is independent and has no no link with the...
Answer the following four sub-questions. Each sub-question is independent and has no no link with the other sub questions. a) Two neutral spheres are spaced 3 m apart. Calculate how many electrons must be transferred from one sphere to another so that they each experience a force of 14 N, and say whether the forces will be attractive or repulsive. b) Calculate the uniform electric field to be applied parallel to a moving proton at 2⋅106 m / s in...
Python #For question 1 and 2 you may not use ''' ''' Question 1 Print the...
Python #For question 1 and 2 you may not use ''' ''' Question 1 Print the messages below without using variables. Output must be 2 lines identical to below: What is the snake's favorite language? "I love Python", said the snake. Question 2 Write a python statements to match the 5 lines of output below. Use a single print statement to produce the list of 4 languages The 3 most popular programming languages of 2020 are: 1.         Python 2.         Javascript 3.         Java 4.         C#...
QUESTION 1 (10 Marks- 5 each)- This question contains two sub questions a and b. Describe...
QUESTION 1 (10 Marks- 5 each)- This question contains two sub questions a and b. Describe five requirements of the COBIT framework. Compare the followings in terms of capacity, expenses, processing power, size and users they support: Supercomputers Mainframe Computers Comparison Element Supercomputers Mainframe Computers
Use Python, please type. A multiple-choice quiz with 5 questions. Each question has 4 possible answers...
Use Python, please type. A multiple-choice quiz with 5 questions. Each question has 4 possible answers labelled A, B, C and D.    After displaying the first question and the 4 possible answers, the user is asked to enter their choice. If their choice is correct, add 1 to the score, then display the next question and its 4 possible answers. At the end of the quiz, display their score out of 5, their score as a percentage, and if...
There are 2 different questions, and the data table is below each question. Please answers them...
There are 2 different questions, and the data table is below each question. Please answers them all A drug test is administered to 10000 individuals as indicated in the contingency table below. Determine the specificity, the sensitivity the PPV and NPV of the test. Also give the prevalence of drug use in the population. Would you trust a positive result for this test (meaning does this accurately indicate that you are a drug user?) Would you trust a negative result?...
1-2 paragraphs per question) 1) Compare and contrast the different U.S. Census spatial definitions of sub-urban...
1-2 paragraphs per question) 1) Compare and contrast the different U.S. Census spatial definitions of sub-urban areas we discussed in class. How are they defined and what do they help economists research urban/regional topics? 2) Compare and contrast the formation of trading cities versus factory cities. How do each form, how do they differ, and what relationships do they share? 3)What are the possible downsides of using congestion tools to prevent excessive highway demand? Fully explain these downsides and how...
how to check if there are keys with the same values in a dictionary. python 3.0...
how to check if there are keys with the same values in a dictionary. python 3.0 for example: data = {'size': 4, 'entrance':(0, 0), 'exit':(0,0)} since the entrance and exit keys have the same value, i want the function to return None.
Short Question 2 (16 marks, 2 marks per sub-question) Fly Ltd is a manufacturer making smart...
Short Question 2 (16 marks, 2 marks per sub-question) Fly Ltd is a manufacturer making smart watches for some local wholesalers. Its fiscal year end falls on 31 December. The company uses standard costing. The cost driver for variable manufacturing costs is production volume. The cost driver for variable selling expenses is sale volume. The company writes off variances to cost of goods sold in the year in which they occur. For both 2018 and 2019, the budgeted price and...
Task 2 requires you to accurately complete the activities described in each question. Complete the answers...
Task 2 requires you to accurately complete the activities described in each question. Complete the answers in your own Excel document, putting your name at the top along with the Task and Task letter appropriate to each answer and submit below for your Assessor. a) Make the Journal entry to record the sale of merchandise that cost $6,000, for $10,000 cash. b) Record journal entries for the following transactions. Purchased office furniture for $3,200, agreed to pay the entire amount...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT