Quote:
|
Originally Posted by UnKnown X
Yet another question: How would I make it write the line number next to the fibonacci number, and then ignore it (the line number)?
I.e:
1: 1
2: 1
3: 2
4: 3
5: 5
6: 8
7: 13
8: 21
9: 34
...
|
I'm not quite sure what you mean. Is the above "code" meant as input from a file, or output from your python program?
To output it, you can use the enumerate function, which encodes a running count into any sequence:
for number, line in enumerate(file):
print "%d: %s" % (number, line),
To input it, you can use the split function, which divides a string based on a specified delimiting character:
for line in file:
number, data = line.split(":")