On 02/02/2014 04:08 AM, adrian wrote:
Hello community,
Newbie here. I have a data (.dat) file with integers (2,9,1,5,7,3,9) in it just
as shown.
My instructions are to sort the numbers and rewrite them back to the data file.
*here is my code:**
*
lab3int=[2,9,1,5,7,3,9]
lab3int.sort()
print(la
Alan Gauld wrote:
> You need a loop such as
>
> for item in lab3int:
>intFile.write( str(item) )
You also need to separate the values, with a space, a newline or whatever.
So:
for item in lab3int:
intFile.write(str(item))
intFile.write("\n")
This can be simplified to
for item in
On 02/02/14 03:08, adrian wrote:
Newbie here. I have a data (.dat) file with integers (2,9,1,5,7,3,9) in
it just as shown.
In your code below you use a hard coded list not a data file?
lab3int=[2,9,1,5,7,3,9]
lab3int.sort()
print(lab3int)
So far so good.
lab3int=open('lab3int.dat','w')