In: Computer Science
IN PYTHON: Write a program that displays the lines from the total.txt file in the following output. Use a try catch phrase to check for errors. Use only one function for this portion [main()]. Remember to use Python. Sample output below:
19
16, 29
3, 30
4, 34
Please upvote if you are able to understand this and if there is any query do mention it in the comment section.
CODE:
try:#using try and except for exception handling
f = open('total.txt', 'r')#opening the file total.txt in read mode
data = f.read()#using the read function to reda the contents of file
print(data)
except:#If no file is found then except will be executed
print("No file with \'total.txt\' is found")
total.txt
OUTPUT:
If this was supposed to be done in any other way or something else was expected in this then please mention it in the comment section otherwise please upvote.