Question: Question 1 : Use any online compiler to answer the below questions and provide screenshots for the code, output, and file. [ This provides evidence

Question 1: Use any online compiler to answer the below questions and provide screenshots for the
code, output, and file.
[This provides evidence for PC 1.1-1.2]
a) Write a Python program that creates a file named data.txt using 'x' mode.
b) Write to this file using the 'w' mode the names of 5 friends (each on a line)
c) Read the content of the file using the 'r' mode, and print them in the console.
d) Append to the file the names of 2 more friends using the 'a' mode.
[This provides evidence for PC 1.3]
e) Using the read() function, read the first 10 characters of the file.
f) Using the readline() and loops, read only the first 4 lines of the file.
[This provides evidence for PC 1.1-1.2]
g) Using the 'w' mode, write the name of your favorite subject to the file. Explain what happens to
the content of the file.(show the output )
Question 1 : Use any online compiler to answer

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!