Question

To insure that file output is written to the disk you need to execute what method?...

To insure that file output is written to the disk you need to execute what method?

a. commit()

b. write()

c. close()

d. complete()

The following is called the ________ of a function.

def myFunction(x,y) :

a. header

b. footer

c. sentinel

d. index

True or False: A commonly used program that uses regular expressions is grep.

True or False: In Python exception handling provides a mechanism for passing control from the point of the error detection to a handler than can deal with error.

True or False: A stub function is a function that acts as a placeholder and returns a simple value so another function can be tested.

What two items do you need to specify when reading a file in Python?

a. a file name and file properties

b. a file name and mode

c. a file name and size

d. a file name and data type

What happens if you try to open a file for input(read mode), but that file does not exist?

a. A default file, data.txt, is created as a new empty file

b. The program raises an exception

c. All attempts to read from the file return an empty string

d. All attempts to read from the file return random values

Assume string s = "red yellow blue". You then use y = s.split() to convert string s into a list. Which statement would print "blue"?

a. print(s[0])

b. print(y[1])

c. print(y[2])

d. print(s[2])

e. none of the above

The name of this function is ____________.

def m(x, y) :

z = x + y

return z

a. m

b. x

c. y

d. z

For this code, what is the point of this line: global total.

total = 0

def main() :

global total

avg = 0

for i in range(6):

total += i * i

avg = total / i

print (""Total, Avg"", total, avg)

a. "It does nothing, and could be removed without consequence"

b. it tells us that the local variable total is off limits

c. it is there to remind us that total is a local variable

d. it allows modifying the global variable total inside function

Which of the following is NOT a good practice when developing a computer program?

a. Put as many statements as possible into the main function and make it a giant jumble of code.

b. Document the purpose of each parameter.

c. Decompose a program into many small methods.

d. Place code that is used multiple times into a separate function.

A file has been opened for writing. Which of the following writes these 2 words, each word on a separate line. "Hello World"

a. outfile.print("Hello\n", "World\n")

b. outfile.write("Hello\n", "World\n")

c. outfile.print("Hello\n\World\n")

d. outfile.write("Hello\nWorld\n")

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answers :

1 . b

2 . a

3 . True

4 . True

5 . True

6 . b

7 . b

8 . c

9 . a

10 . d

11 . a

12 . d

Explanation :

1 . write() is used in python to write contents to a file

2 . def function_name() is always the head of the function.(It is a start of function)

3 . True , Explanation provided in statement it self.

4 . True , Explanation provided in statement it self.

5 . True , Explanation provided in statement it self.

6 . open('filename','mode') mode = 'r','w',.... [filename,mode are must to open a file]

7 . Program rises a exception if file does not exist but won't create it.

8 . List indices starts from 0.Since list has 3 words, Last word can be accessed with 2.

9 . function name comes after def.[Here,m]

10 . In order to modify global variable inside a function,It has to be declared as global inside a function.Here,It is declared so can be modified.

11 . a is not a good practice.

12 . write is used to write content to a file.To write in new lines '\n' is used.

Note :

  • Any doubts,feel free to comment here
Add a comment
Know the answer?
Add Answer to:
To insure that file output is written to the disk you need to execute what method?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am having a little trouble with my Python3 code today, I am not sure what...

    I am having a little trouble with my Python3 code today, I am not sure what I am doing wrong. Here are the instructions: and here is my code: update: I have seen I did not close x in sumFile and I am still only getting a 2/10 on the grader. any help appreciated. Lab-8 For today's lab you going to write six functions. Each function will perform reading and/or write to a file Note: In zybooks much like on...

  • 1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write...

    1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write a Python program that prompts the user for a sentence, then replaces all the vowels in the sentence with an asterisk: '*' Your program should use/call your isVowel function from Assignment_Ch06-01. You can put the isVowel() function in a separate .py file, without the rest of the Ch06-01 code, and then import it. 6-01 CODE: def isVowel(x):     if x in "aeiouyAEIOUY":         return True     else:...

  • Python Please, If possible, please continue with/ use code already given File Commands: u/a Write a...

    Python Please, If possible, please continue with/ use code already given File Commands: u/a Write a function named, file_commands, that takes the name of a file as a parameter. The function processes the contents the file as follows: For file lines that begin with the letter 'a', calculate & print the integer average of the numbers on the line. For file lines that begin with the letter 'u', print the upper case format for each word following the u. Sample...

  • I need this python program to access an excel file, books inventory file. The file called...

    I need this python program to access an excel file, books inventory file. The file called (bkstr_inv.xlsx), and I need to add another option [search books], option to allow a customer to search the books inventory, please. CODE ''' Shows the menu with options and gets the user selection. ''' def GetOptionFromUser(): print("******************BookStore**************************") print("1. Add Books") print("2. View Books") print("3. Add To Cart") print("4. View Receipt") print("5. Buy Books") print("6. Clear Cart") print("7. Exit") print("*****************************************************") option = int(input("Select your option:...

  • Del Python is (choose all that apply) ext) call takes three arguments, senders e-mail receiver's e-mail and the e-mail text. A) Used in Scientific Applications D) Compiled Language 7, help) f...

    Del Python is (choose all that apply) ext) call takes three arguments, senders e-mail receiver's e-mail and the e-mail text. A) Used in Scientific Applications D) Compiled Language 7, help) function call will open a different shell in Python shell We can run Python applications using Python Shell, IDLE and Command Line. A) True Dy False AT Thue B) False 8. Suppose that you have a Python file myApplication.py. You can run it by (choose all that apply) -3. To...

  • (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that...

    (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that you have been provided on Canvas. That file has a name and 3 grades on each line. You are to ask the user for the name of the file and how many grades there are per line. In this case, it is 3 but your program should work if the files was changed to have more or fewer grades per line. The name and...

  • Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following:

    Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following:How to format each dictionary item as a text string in the input file.How to covert each input string into a dictionary item.How to format each item of your inverted dictionary as a text string in the output file.Create an input file with your original three-or-more items and add at...

  • Python program Use the provided shift function to create a caesar cipher program. Your program s...

    python program Use the provided shift function to create a caesar cipher program. Your program should have a menu to offer the following options: Read a file as current message Save current message Type in a new message Display current message "Encrypt" message Change the shift value For more details, see the comments in the provided code. NO GLOBAL VARIABLES! Complete the program found in assignment.py. You may not change any provided code. You may only complete the sections labeled:#YOUR...

  • Python: 1) Consider the following code segment: try : inputFile = open("lyrics.txt", "r") line = inputFile.readline()...

    Python: 1) Consider the following code segment: try : inputFile = open("lyrics.txt", "r") line = inputFile.readline() print(line) _____________________ print("Error") What should be placed in the blank so that the program will print Error instead of crashing if an exception occurs while opening or reading from the file? Group of answer choices a- except RuntimeError : b- except EnvironmentError : c- except IOError : d- except IndexError : 2) Consider the following code segment: line = "hello world!" parts = line.split()...

  • ,,1. Which of the following statments are valid C++ statements? A) cout << "Hello World" :...

    ,,1. Which of the following statments are valid C++ statements? A) cout << "Hello World" : B) cout << Hello World; C) cout << "Hello " << "World" ; D) cout << "Hello" << "World" ; 2. What is the difference between the literals 'A' and "A"? ,3. Read the input from user; Check for valid entries If input is invalid: print an error message; else: calculate the result and print to the console; exit; The code snippet above may...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT