whats wrong in this code | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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 Antworten
+ 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