Write a program that performs the following:
- Reads from the file "myfile.txt" using readlines()
- Prints out the contents of the file "myfile.txt", that was read
into a list by readlines(). Note that this should not look like a
list, so you will need to loop through the list created by
readlines and print the text.
- Use the try/except method to create the file if it does not
exist
- If the file does not exist, prompt the user in a loop to enter a
line of text. End the loop when the user types "end"
- Save the text to a file called "myfile.txt" using write()
- Don't forget to close the file.
#when file not exist

#running second time

code:
def main():
#read file in try catch mode
try:
#open file in read mode
read_file = open("myfile.txt","r")
#read lines as list
lines = read_file.readlines()
#print each line content
for line in lines:
print(line)
#close the file
read_file.close()
except FileNotFoundError:
#if file not exist
#create a file in write mode
write_file = open("myfile.txt","w")
#ask user to enter the lines
while True:
line = input("Enter line : ")
#check if user enters end
if line.lower() == "end":
break
#write line into file with a new line
write_file.write(line+"\n")
#close the file
write_file.close()
main()
Write a program that performs the following: - Reads from the file "myfile.txt" using readlines() -...
Write a program to read a text file, place each line it reads into an array. Then print the array’s contents one line at a time. Then add to the end of the text file “Success”. Use error exception handling and if the text file does not exist print "Error file not found." Always print "It worked." as part of the try clause. Upload a zip folder file of the .py and text file. roses are roses are red, violets...
//Done in C please!
//Any help appreciated!
Write two programs to write and read from file the age and first
and last names of people. The programs should work as follows:
1. The first program reads strings containing first and last
names and saves them in a text file (this should be done with the
fprintf function). The program should take the name of the file as
a command line argument. The loop ends when the user enters 0, the...
Following should be done in C++: Create a program that reads a text file and prints out the contents of the file but with all letters converted to uppercase. The name of the file to be read by the program will be provided by the user. Here are some example session: Contents of "data.txt": Hello, World! User input: data.txt Program output: HELLO, WORLD! Contents of "data.txt": tHiS FiLe HaS mIxEd CaSeS User input: data.txt Program output: THIS FILE HAS MIXED...
Exercise 1: Create a file by using any word processing program or text editor. Write an application that displays the file's name, size, and time of last modification. Save the file as FileStatistics.java. Exercise 2: Create a file that contains your favorite movie quote. Use a text editor, such as Notepad, and save the file as Quote.txt. Copy the file contents and paste them into a word processing program, such as Word. Save the file as Quote.doc. Write an application...
Write a program that first reads in the name of an input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words and their frequencies (the number of times each word appears in the file) without any duplicates. Ex: If the input is: inputl.csv and the contents of input1.csv are: hello, cat, man, hey, dog, boy, Hello, man, cat, woman, dog, Cat, hey, boy the output is: hello 1 cat 2 man...
Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program...
(Python 3) Write a program that reads the contents of a text file. The program should then create a dictionary in which the keys are individual words found in the file and the values are the number of times each word appears and a list that contains the line numbers in the file where the word (the key) is found. Then the program will create another text file. The file should contain an alphabetical listing of the words that are...
Write a program that performs the following: 1. Presents the user a menu where they choose between: a. Add a new student to the class i. Prompts for first name, last name ii. If assignments already exist, ask user for new student’s scores to assignments b. Assign grades for a new assignment i. If students already exist, prompt user with student name, ask them for score ii. Students created after assignment will need to...
Question 7 (a) Write a C program that performs the following tasks: 1. Create a text file to store a list of numbers. 2. Read a number entered by a user and store it into the text file until a negative number is entered. (b) Write a C program that performs the following tasks: 1. Open the text file that contains a list of numbers. 2. Print the list of numbers stored in the text file on the screen.
Write an assembly language 32 bit program that reads in lines of text by a .txt file and read in from the user and prints them diagonally. Using good commenting.