Simple script crashes IDLE

davbucko davbucko at
Sat Aug 31 23:34:20 CEST 2002

Hi all,

I am entirely new to python (having only picked it up this afternoon), and
so doubtless I am doing something *really* stupid.  If it is a case of rtfm,
I apologise.  However, here we go.

My first script worked ok for a few tries, and then stopped working
suddenly.  However, it did not have syntax errors or anything, but just
crashes the Python.exe (or whatever it's called) program when I ctrl+F5 it
from IDLE (or try to run it from the command prompt, or from WinPython, or
whenever in fact).  If I change it so that there are obvious syntax errors,
it simply tells me about the syntax error and doesn't run it.  But when all
is "well", it crashes the machine.

What have I done wrong?

class Powers:

  def __init__(self):
    self.list = {}
    for i in [2,3]:
      self.list = {i: self.getThreeDigitPowers(i)} #Oh yeah, are you allowed
to do this?

  def getThreeDigitPowers(self,power):
    number = 0
    i = 1
    powerlist = []
    while number < 1000:
      number = i**power
    del powerlist[-1]
    return powerlist
#End of class

a = Powers()

print "Number of Squares under 1000: ",len(a.list[2])
print "List of Squares: \n"
for i in a.list[2]:
  print i
print "\nNumber of Cubes under 1000: ",len(a.list[3])
print "List of Cubes: \n"
for i in a.list[3]:
  print i

#End of file

Thanks in advance


More information about the Python-list mailing list