Hello I'm working on files and extension in my python code along with text files. In my text file I have to make "data1.txt". What would I need to write in my python code to create both possible outputs? Because when I add count, it includes line numbers but I only need to see that the second time I open the code, when I reopen it. And at the end where it says there are 8 lines, do I include that in the code or text file? I also have to include def main().
Hello I'm working on files and extension in my python code along with text files. In my text file I have to make "data1.txt". What would I need to write in my python code to create both possible outputs? Because when I add count, it includes line numbers but I only need to see that the second time I open the code, when I reopen it. And at the end where it says there are 8 lines, do I include that in the code or text file?
I also have to include def main().
Here is the text from data1.txt:
This is a data file
When you process your data file remember to strip the end of the line character.
rstrip method is a string method that strips a character from end of the string
line1 = line1.rstrip('\n')
To handle any potential error use try/except/else
The total number of lines is not a part of the data1.txt file.
The else part in your code is not required as you're trying to handle a case where the input is something other than data1.txt which is unnecessary.
The correct code has been attached below.
Step by step
Solved in 3 steps with 1 images