0
class Packagings:
    def __init__(self):
        self.length=0
        self.deckle=0
        self.tmp=0
        self.flute=[]
        self.gsm=[]
        self.t_weight=0
        self.weight=0

    def read_values(self):
        print """Select Type Of Paper
               1.3 Ply
               2.5 Ply
               3.7 Ply
               """
        self.type=input("Enter the type:")
        self.l=input("Enter Length:")
        self.b=input("Enter Breadth:")
        self.h=input("Enter Height:")
        self.flap=input("Enter Flap:")


    def ply_read_values(self):
        for i in range(0,2):
            self.flute[i]=input("Enter flute:")
            self.gsm[i]=input("Enter Gsm:")
            self.weight[i]=self.tmp*(flute[i]*gsm[i])
            self.t_weight=self.t_weight+self.weight[i]

    def do_calc(self):
        self.length=(2*self.l+2*self.b+self.flap)/1000
        self.deckle=(float(self.h+self.b))/1000
        self.tmp=self.length*self.deckle


    def print_value(self):
        print self.length
        print self.deckle
        print self.t_weight

#Main Function
obj=Packagings()
obj.read_values()
obj.do_calc()
obj.ply_read_values()
obj.print_value()

When I run this program, I get the following error. I cannot find how the list assignment goes out of range. Could you guys go through my program and tell me where I went wrong? For me the list seems fine. How does it go out of index?

Traceback (most recent call last):
  File "C:/Python27/packagings.py", line 47, in <module>
    obj.ply_read_values()
  File "C:/Python27/packagings.py", line 27, in ply_read_values
    self.flute[i]=input("Enter flute:")
IndexError: list assignment index out of range
trusko
  • 5
  • 1

2 Answers2

4

self.flute is initialized to an empty list, so it has no elements you can reset. Use self.flute.append and similarly for your other lists.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
1

assuming to your code, you need to replaceself.weight=0 with self.weight=[] i think it is your problem

Dmitry Zagorulkin
  • 8,370
  • 4
  • 37
  • 60