Which of the following statements about the write method are TRUE assuming outfi
ID: 3595072 • Letter: W
Question
Which of the following statements about the write method are TRUE assuming outfile object has been created, e.g. outfile = open('somefiletxt: 'w')? (check all that apply) If after opening the file, the program contains the statement outfile.write(sales:'35.75) then somefile.txt will contain sales:35.75 If after opening the file, the program contains the statement write( 123.4) then somefile.txt will contain 123.4 If after opening the file, the program contains the statements outfile.write('sales:+35.75) outfile.write" another line?) then somefile.txt will contain sales:35.75 another line? If after opening the file, the program contains the statement outfile.write(John Hume) then somefile.txt will contain John HumeExplanation / Answer
1) False
In python the write() function takes exactly one parameter , ie here two argument is given so it will throw a TypeError ie is write() takes exactly one argument and two is given
2) False
In this case you called the function write() with out an object , ie python compiler will look for user defined function with the name write() ,and finaly it can't find a function with that name so there will be a NameError.
ie , it will return name write is not defined.
3) True
after executing the code
outfile.write('sales:'+'35.75')
outfile.write(' another line?')
somefile.txt will contain sales: 35.73 another line?
because in "outfile.write('sales:'+'35.75') " python use + to concate the strings so the two arguments will join to become a single one ie addition of two strings takes place in python (3) outfile.write('sale:' '35.75') will also give the same result , here + is like operator overloading
4) True
Here wirte function simply write the contets ie passed as it's argument it will write to a object file
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.