0

whats wrong in this code

class arr: def __init__(self,l): self.l=l def __add__(self, other): i=0 p=[] if len(self.l)==len(other.l): while i<len(self.l): p.append(self.l[i]+other.l[i]) return p p=arr([1,2,3]) q=arr([1,2,3]) print(p+q)

27th Sep 2019, 6:55 AM
Siddharth Acharya
Siddharth Acharya - avatar
2 Respostas
+ 3
You forgot to increment i within that while loop, better option is to use a for loop so you won't forget stuff like this in the future!
27th Sep 2019, 7:04 AM
jtrh
jtrh - avatar
+ 1
oh thanks👍👍
27th Sep 2019, 1:27 PM
Siddharth Acharya
Siddharth Acharya - avatar