Computer Science, asked by amal2915, 6 months ago

write a python program to accept a line from the user and store that in a file "story.txt"​

Answers

Answered by sfayizmuhammed
0

Answer:

print("Input whatever line you want")

line = input()      # use the input() keyword to get input from the user

open("story.txt", x)          # 1

file = open("story.txt", w)    #2

file.write(line)    #3

Explanation:

#1 = we are using the open method to create the file named story.txt (you can skip this if the file already exists). The open keyword takes in two arguments, first the file name and the second is what to do with the file. we use the 'x' to create a non existent file.

#2  = now that we have created the file. we need to write to it using the same line we used above but with 'w' instead of 'x'. we are making a variable before writing this line to access it later in the script

#3 = now let's access the file variable and use the write keyword to write whatever we want to the file.

The Major three arguments to use while working with files.

'x' = to create a file

'w' = to write stuff to a file

'r' = to just read stuff from the file

you can message me if you have any doubts. : )

Similar questions