Answer the question
In order to leave comments, you need to log in
What is wrong with my code (python)?
friends = ['Sergey', 'Sonya', 'Dima', 'Alina', 'Egor']
index = print(friends[3])
print('Hi, ' + friends[index] + ', I'm Anfisa!' )
Add the code so that your program prints the phrase Hello, Alina, I'm Anfisa!
All that is required is to assign a value to the index variable so that Alina is selected from the list.
Do not change the line with the print() call.
this is the error: Traceback (most recent call last):
File "main.py", line 3, in
print('Hi, ' + friends[index] + ', I'm Anfisa!')
TypeError: list indices must be integers or slices , not str
Answer the question
In order to leave comments, you need to log in
friends = ['Сергей', 'Соня', 'Дима', 'Алина', 'Егор']
index = 3
print('Привет, ' + friends[index] + ', я Анфиса!')
Well, it says that
the list index cannot be a string, but a number or a slice...
Why do you enter print with the lines of the sheet as an index?
Of course, you give out the sheet friends, and also enter print(friends[3]) there, this is NoneType
friends = ['Sergey','Sonya','Dima','Alina','Egor ']
index = friends[3]
print('Hi, ' + index + ', I'm Anfisa!')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question