Respuesta :
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, open(). 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 open("greeting.txt", "w") will create a text file named "greeting.txt" (Line 1)
To fill up the content in the greeting.txt, we use write() method. Just include the content string as the argument of the write() method. (Line 2)
At last, we use close() method to close the opened file, outfile. This will release the system resource from the outfile.
The program is an illustration of file manipulations.
File manipulation involves reading and writing to a file.
The program in Python where comments are used to explain each line is as follows:
#This creates the greeting.txt file for a write operation
myFile= open("greeting.txt", "w")
#This writes "Hello World!" to the file
myFile.write("Hello World!")
#This closes the file
myFile.close()
At the end of the program, "Hello World!" is written into the file.
Read more about similar programs at:
https://brainly.com/question/7238365