[Tutor] List all possible 10digit number

Dave Angel d at davea.name
Sat Sep 1 07:14:14 CEST 2012


On 08/31/2012 10:38 PM, Scurvy Scott wrote:
> Now I've got
> 
> A = 1000000000
> I = raw_input("file name> ")
> TheFile = open(I, 'w')
> 
> TheFile.truncate
> def allten(a):
>     while a < 9999999999:
>         a =  + 1
>         TheFile.write(a)
> allten(a)
> 
> The result is:
> Open file 'file.txt', mode w at 0xb7331ee8
> Traceback line 13 etc....
> 

Top-posted again.

You stop the traceback before showing anything interesting.  i don't see
13 lines, so I have to totally guess which line is getting the error,
and also what error it's getting.  Paste the code and the traceback
directly, and if that means you have to get email working on whatever
machine you're running Python on, then do so.  Retyping on your iphone
isn't productive for anyone.

There are a pile of typos in that code.  Are they just because you
retyped, or is that really what you tried?

1) TheFile.truncate doesn't call anything.  The line is useless without
parentheses.  Of course, that doesn't matter much, since the open
already truncated it.

2)  allien(a)    There's no such variable as 'a' defined.  you do have
one called A

3) write() takes a string.  You're passing it an int or long.  Convert
with the str function, or other method, depending on what you really want.

4) Once you fix #2 and #3, the first value you write will be 10000001
That's off by one.  As i said in my last message, you should swap the
two lines.  And once you do, you'll end one value too low.  As I also
said there, you should test the loop with smaller numbers.



-- 

DaveA


More information about the Tutor mailing list