2012-06-21 42 views
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() 

當我運行此程序時,出現以下錯誤。我無法找到列表分配如何超出範圍。你們能否通過我的計劃並告訴我我哪裏出了錯?對我來說這份清單似乎很好。它如何脫離索引?IndexError:列表分配索引超出範圍

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 

回答

4

self.flute被初始化爲一個空的列表,所以它沒有可以重置的元素。使用self.flute.append和其他列表類似。

+0

感謝馬安真正幫助 –

1

假設你的代碼,你需要self.weight=[] 更換self.weight=0我認爲這是你的問題

+0

雅那是另外一個錯誤,我沒有注意到......謝謝親愛的幫我解決它 –

相關問題