Why cant i get the index number?
The user looks for an age, the method should then look for that number in the age section of the list and if it does exist there it should print out the position of that value https://code.sololearn.com/cHSG42NUYWxS/?ref=app
Lenoname Show your code with my fixes so I can see how you manage to get two results. The function I provided works as per your requests. While not really practical, I would write it differently.
You've made too many mistakes: 1. The find_age() function was not called; 2. The required element was not specified in the .index(?) method; 3. Have not created a complete list of ages. def find_age() : f = int(input('Find age: ')) for i in personList : c.append(i.age) #debug if i.age == f : print(c.index(f)) #debug find_age() #debug
FF9900 i dont know if has something to do with what u said but it says valueerror and True is not in the list, worked fine on solo but replit once again…
FF9900 prints out only one position even if there are multiple people with the same age
FF9900 Would changing this a lil bit have the same result? def find_age() : #f = int(input('Find age: ')) #print([a for a in personList if a.age == f])
FF9900 the code u wrote works,i’m just curious about the code with print, if i were to change some things it might have worked also, since it prints out the right values but not their indexes
FF9900 i did and tried to print(index(mylist)) but crashed
FF9900 f = int(input()) m = [a.age for a in personList if a.age == f] print(m.index(f)) —>outputs 0
f = int(input()) m = [a for a in personList if a.age == f] print(m.index(f)) —> made it crash
Solo i tried your version, it gave me 2 numbers of the same value for example: 0 0, but thats not possible