Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

why ? ( list index out of range )

$
0
0
Well guys here is my code, i know its incomplete and there is a never ending loop but my problem is that from time to time i get error ( list index out of range) why ? :(


import random



lists=[[150, 9, 'drop'], [35,13,"cage"],[200,153,"lust"],[160,50,"google"],[60,15,"gun"],[45,68,"razor"],[60,27,"armor"] ]
x=random.sample(lists,  3)
theitems=[]
for i in range(len(x)):
        theitems.append(x[i][2])
print theitems
tw=0
tv=0
while True:
    
    
    epilogi=raw_input("choose")
    for i in range(len(theitems)):

          if theitems[i]==epilogi:
                      
              tw=tw+x[i][1]
              tv=tv+x[i][0]
              theitems.remove(theitems[i])
              x.remove(x[i])
    print theitems,x



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>