Check sibling questions

Write a method in Python to write multiple lines of text contents into a text file, ''MYFILE.TXT'' line.

 

Answer:

def write():

f=open("MYFILE.txt",'w')

while True:

line=input("Enter a line: ")

f.write(line)

more_line=input("Are there more lines? Enter Y for yes and N for no: ")

if more_line == 'N':

break

f.close()

Question 5-Write a method in Python - Teachoo.JPG

Introducing your new favourite teacher - Teachoo Black, at only ₹83 per month


Transcript

Question 5 Write a method in Python to write multiple lines of text contents into a text file, ''MYFILE.TXT'' line. declaring function count( ) Taking a user input as ‘line’ for writing it to the file. Invoking function write( ) opening the text file in read mode and assigning it to file_object ‘f’ Writes ‘line’ to the text file. Output

CA Maninder Singh's photo - Expert in Practical Accounts, Taxation and Efiling

Made by

CA Maninder Singh

CA Maninder Singh is a Chartered Accountant for the past 12 years. He also provides Accounts Tax GST Training in Delhi, Kerala and online.