← Python from Scratch Lesson 75 of 78 · 5 XP

Warm-up: write a word warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

To write to a file, open it in "w" mode (write). If the file didn't exist, it is created:

with open("hello.txt", "w", encoding="utf-8") as f:
    f.write("Hello")

Careful: "w" erases whatever was in the file before.

Task. Write a function write_word(path, word) that writes the word word into the file path. Nothing else needs to go into the file.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.