Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Виклик: Отримання Інформації з Вкладеного Списку | Інші типи даних
Вступ до Python

book
Виклик: Отримання Інформації з Вкладеного Списку

Завдання

Swipe to start coding

Вам надано список people, який включає підсписки з іменами та віком п'яти осіб, як показано нижче:

Ім'яВік
Alex23
Noah34
Peter29
John41
Michelle35

Щоб витягти конкретну інформацію за допомогою індексації, виконайте наступні кроки:

  • Збережіть повну інформацію про 4-ту особу в списку у змінній fourth_person.
  • Збережіть ім'я першої особи в списку у змінній first_name.
  • Збережіть вік п'ятої особи в списку у змінній fifth_age.
  • Використовуйте індексацію для вирішення цього завдання.

Рішення

# Initial list
people = [["Alex", 23], ["Noah", 34], ["Peter", 29], ["John", 41], ["Michelle", 35]]

# Write your code here
fourth_person = people[3]

first_name = people[0][0]

fifth_age = people[4][1]

# Testing
print(f"Full info about the fourth person: {fourth_person};\nThe name of the first person: {first_name};\nThe age of the fifth person: {fifth_age}.")
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 5
# Initial list
people = [["Alex", 23], ["Noah", 34], ["Peter", 29], ["John", 41], ["Michelle", 35]]

# Write your code here
fourth_person = ___

first_name = ___

fifth_age = ___

# Testing
print(f"Full info about the fourth person: {fourth_person};\nThe name of the first person: {first_name};\nThe age of the fifth person: {fifth_age}.")
toggle bottom row
some-alt