Answer:
The solution code is written in Python 3 as below:
- outfile = open("greeting.txt", "w")
- outfile.write("Hello World")
- outfile.close()
Explanation:
To create a simple text file in Python, we can use Python built-in function, <em>open()</em>. There are two parameters needed for the open() function,
- the file name and
- a single keyword "w". "w" denote "write". This keyword will tell our program to create a file if the file doesn't exist.
The statement <em>open("greeting.txt", "w")</em> will create a text file named "<em>greeting.txt</em>" (Line 1)
To fill up the content in the greeting.txt, we use <em>write()</em> method. Just include the content string as the argument of the <em>write()</em> method. (Line 2)
At last, we use <em>close() </em>method to close the opened file,<em> outfile</em>. This will release the system resource from the<em> outfile.</em>