Write a Daily Report File

Easy ⏱ 8 min 72% acceptance ★★★★☆ 4.2
Write save_report(path, lines) that writes each string from lines to the file at path, one per line, overwriting any existing content. Every line in the file must end with a newline character.

Examples

Example 1
Input
save_report('report.txt', ['sales: 90', 'cost: 40'])
Output
file contains 'sales: 90\ncost: 40\n'
Explanation

Mode 'w' truncates and rewrites the file.

Constraints

  • Open in 'w' mode.
  • Each line ends with \n.

Topics

File Handlingwriting

Companies

AccentureCognizantWipro

Hints

Hint 1

f.write(line + '\n') in a loop, or f.writelines with a generator.

Hint 2

The with block handles closing.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.