13. Write function quote() that takes as input the name of a file (as a string) and an index i (as an integer). The file will contain quotes, one per line. The function should open the file, read the file, close the file, and return the i-th quote (i.e. the i-th line in the file), assuming that the quote numbering starts at 0. Test your solution on file Wilde_Quotes.txt. >>> quote("Wilde_Quotes.txt", 5) 'At twilight, nature is not without loveliness, though perhaps its chief use is to illustrate quotations from the poets.\n' >>> quote("Wilde_Quotes.txt", 0) 'A little sincerity is a dangerous thing, and a great deal of it is absolutely fatal.\n' >>> quote("Wilde_Quotes.txt", 23) 'Patriotism is the virtue of the vicious. \n' >>>
13. Write function quote() that takes as input the name of a file (as a string) and an
index i (as an integer). The file will contain quotes, one per line. The function should
open the file, read the file, close the file, and return the i-th quote (i.e. the i-th line in the
file), assuming that the quote numbering starts at 0. Test your solution on
file Wilde_Quotes.txt.
>>> quote("Wilde_Quotes.txt", 5)
'At twilight, nature is not without loveliness, though
perhaps its chief use is to illustrate quotations from the
poets.\n'
>>> quote("Wilde_Quotes.txt", 0)
'A little sincerity is a dangerous thing, and a great deal
of it is absolutely fatal.\n'
>>> quote("Wilde_Quotes.txt", 23)
'Patriotism is the virtue of the vicious. \n'
>>>
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images