For example, if the input file is:
def main():
for i in range(10):
print("I love Python")
print("Good bye!")
Then the output would be:
1 def main():
2 for i in range(10):
3 print("I love Python")
4 print("Good bye!")
I have difficulty in adding lines to each line. My program is:
filename = input("Please enter a file name: ")
count = 0
openfile = open(filename, "r")
for lines in openfile:
linenumbers = openfile.write(str(count)+''+lines)
count += 1
print(count)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…