THE CODE MUST BE PYTHON
# create a file with the name <last_three_digits_of_your_empl_id>.txt
# write into this file two lines:
# 1. your name
# 2. your hobby
# close this files.
#
# open the created files <last_three_digits_of_your_empl_id>.txt,
# add a third line to this file with today's date.
# close the file.
I have used place holders for the entries to be written in the file and for the filename also. Please use appropriate names wherever required.
Have a look at the code below. I have put comments wherever required for better understanding.
The file will look like this...
# this command will open the file if any file is present with the name specified or it will create a new file.
file = open('123.txt','w')
# This command will write the name in file
file.write("Write Your Name Here \n")
# This command will write the hobby in file
file.write("Write Your Hobby Here \n")
# This command will close the file
file.close()
# This command will open the file and new entries will be appened at the end of current file, it will not over write the previous content
file = open('123.txt','a')
# This command will write the date
file.write("Write Today's Date")
# this command will close the file.
file.close()
Happy Learning!
Get Answers For Free
Most questions answered within 1 hours.