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
6 Answers
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
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
0
Lenoname
Do let me know if you require any further information
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
0
My mistake, i had added an extra for loop otherwise it would work fine with the previous version
0
In your previous version, you have appending it to the same list and printing it..