Good day, friends! Please tell me what am I doing wrong? Why do I have sex instead of a surname?

Tourists={'surname':{},'age':{},'sex':{},'eyecolor':{}} n=int(input('Введите количество добавляемых объектов ')) for i in range(0,n,1): Tourists['surname'[i]]=input('Введите фамилию ') Tourists['age'[i]]=input('Введите возраст ') Tourists['sex'[i]]=input('Введите пол ') p=int(input ('Выберите цвет глаз: 1)Зеленые, 2)Карие, 3)Голубые, 4)Серые, 5)Желтые, 6)Черные ')) if p==1: Tourists['eyecolor'[i]]='Зеленые' elif p==2: Tourists['eyecolor'[i]]='Карие' elif p==3: Tourists['eyecolor'[i]]='Голубые' elif p==4: Tourists['eyecolor'[i]]='Серые' elif p==5: Tourists['eyecolor'[i]]='Желтые' else: Tourists['eyecolor'[i]]='Черные' print (Tourists['surname'[i]]) print (Tourists['age'[i]]) print (Tourists['sex'[i]]) print (Tourists['eyecolor'[i]]) 

Here is what it does: enter image description here

  • You probably had this in mind: Tourists['eyecolor'][i]='Зеленые' this also applies to all other calls to Tourists - gil9red

1 answer 1

Because

 'surname'[i] 

when i = 0 is 's'

And you output accordingly: Tourists['s'],Tourists['a'],Tourists['s'],Tourists['e']

  • Yes, this also applies to everything else :) - gil9red