Python 3
please solve all A,B and C, Thank you!
Creating our reference file In our initial example we create a small reference file by executing the following cell. The so-called cell-magic command &$file takes its first argument as a filename and writes the remaining content of the cell to file More about cell magic *%file composers.txt dufay ockeghem josquin Python + Code + Markdown Reading In A we recall different forms of reading text files. These are single-line answers that output some text. A: What single line is used to return the file content as a single string? Not that the string will contain the end-of-line (newline) character '\n' Markdown # YOUR CODE HERE Python assert dufay ockeghem josquin Python
B: What single line is used to return the file content as a Python list of strings. Markdown + Code + Markdown # YOUR CODE HERE Python assert == ['dufay\n', 'ockeghem\n', 'josquin\n'] Python C: This function will return the lines of the file without the 'end-of-line' characters. Use the strip method DE DE DO.. M def get_list_of_lines_without_eol_character(filename): lines = [] for line in open('composers.txt'): # YOUR CODE HERE #*************** return lines get_list_of_lines_without_eol_character('composers.txt') Python assert get_list_of_lines_without_eol_character('composers.txt') == ['dufay', 'ockeghem', 'josquin'] Python
Python 3 please solve all A,B and C, Thank you!
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Python 3 please solve all A,B and C, Thank you!
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!