Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

would like some help please! QUESTION 2 Consider the following Python code, wher

ID: 3588520 • Letter: W

Question

would like some help please!

QUESTION 2 Consider the following Python code, where infile.txt and outfile.txt both exist in the current directory: open ( ' out file. txt ' , 'w ' ) open ( ' infile . txt' , ' r' ) new = old = for line in old: new.write (line) new.write(n) new.close ) old.close ) Which of the following options best describes the purpose or outcome of this code? A copy of the file infile.txt is made (except in double line spacing) and saved as outfile.txt in the current directory. A copy of the file infile.txt is made (except with newline characters removed) and saved as outfile.txt, in the current directory. An exact copy of the file infile.txt is made and saved as outfile.txt in the current directory A copy of the file outfile.txt is made (except in double line spacing) and saved as infile.txt in the current directory. A copy of the file outfile.txt is made (except with newline characters removed) and saved as infile.txt in the current directory. An exact copy of the file outfile.txt is made and saved as infile.txt in the current directory A copy of the file called 'new' is made (except in double line spacing) and saved as 'old' in the current directory A copy of the file called 'new' is made (except with newline characters removed) and saved as 'old' in the current directory An exact copy of the file called 'new' is made and saved as 'old' in the current directory A copy of the file called 'old' is made (except in double line spacing) and saved as 'new' in the current directory A copy of the file called 'old' is made (except with newline characters removed) and saved as 'new' in the current directory An exact copy of the file called 'old' is made and saved as 'new' in the current directory

Explanation / Answer

Question 2

# Opens outfile.txt in writing mode

new = open('outfile.txt', 'w')

#Opens infile.txt in reading mode

old = open('infile.txt', 'r')

# Reading each line from the infile.txt

for line in old:

# Writing line to the outfile.txt with newline

new.write(line);

# Adding one more line

new.write(' ');

# closing outfile.txt

new.close()

# closing infile.txt

old.close()

Answer:

A copy of the file infile.txt is made( except in double line spacing) and saved as outfile.txt in the current directory.

Question 3

a)    Prints all the elements Correct Answer

b) prints indexes from 0 to length(list) - 1, but not the elements in the list Wrong Answer

c) Prints all the elements Correct Answer

d) Prints all the elements Correct Answer

e)   Prints all the elements but not last element Wrong Answer

Question 5

a) char

b) word

c) ord(char)

unicode = []

for char in word:

unicode.append(ord(char))

print unicode

# Produces output as [104, 101, 108, 108, 111]