0

Anyone knows why i get extra unknown positions printed out on the second ”print”?

https://code.sololearn.com/cgqcgRx4pV0A/?ref=app Ignore the comments

28th Feb 2022, 8:56 AM
Lenoname
6 Respuestas
0
Lenoname b = [] c = [] personList = [] class Person: def init(self, name, sex, age): self.name = name self.sex = sex self.age = age def str(self): return f'{self.name},{self.sex},{self.age}' def repr(self): return f'{self.name},{self.sex},{self.age}' # for k in range(3): while True: print('New person ') print('................') while True: try: p = Person(input('Name: '), input('Sex: '), int(input('Age: '))) q = p.name.isalpha() and p.sex.isalpha() and type(p.age) is int if q: break else: print('wrong input') except ValueError: print('wrong input') personList.append(p) if len(personList) + 1 > 3: break
28th Feb 2022, 4:28 PM
B.VIDYADHAR VIJJU
B.VIDYADHAR VIJJU - avatar
0
Lenoname def print_sex(): for i in personList: b.append(i.sex) print('Positions for males: ', [a for a in range(len(b)) if b[a] == 'male']) for i in personList: c.append(i.sex) print('Positions for females: ', [a for a in range(len(c)) if c[a] == 'female']) print_sex() you can follow the below instagram page for more content on coding https://www.instagram.com/anonymous_me_0000/ id:anonymous_me_0000
28th Feb 2022, 4:29 PM
B.VIDYADHAR VIJJU
B.VIDYADHAR VIJJU - avatar
0
Lenoname Do let me know if you require any further information
28th Feb 2022, 4:29 PM
B.VIDYADHAR VIJJU
B.VIDYADHAR VIJJU - avatar
0
B.VIDYADHAR VIJJU why are females added to c? Thats a list for ages, even if i make another list for females, that wont work, i think they should be in the same list so that i get the right index number and order printed
28th Feb 2022, 6:39 PM
Lenoname
0
My mistake, i had added an extra for loop otherwise it would work fine with the previous version
28th Feb 2022, 6:45 PM
Lenoname
0
In your previous version, you have appending it to the same list and printing it..
28th Feb 2022, 6:58 PM
B.VIDYADHAR VIJJU
B.VIDYADHAR VIJJU - avatar