Challenge: Retrieving Information from Nested Tuple
Task
Swipe to start coding
You've been provided with a tuple named people
that holds data on individuals' names, ages, and heights in the format: (('name', age, height), ('name', age, height), ...)
. Here's a snapshot of the data:
Name | Age | Height |
---|---|---|
Alex | 23 | 178 |
Noah | 34 | 189 |
Peter | 29 | 175 |
John | 41 | 185 |
Michelle | 35 | 165 |
Your task is to extract some information:
- In the variable
peters_info
, extract all the information about Peter. - In the variable
johns_height
, extract John's height. - In the variable
alexs_age
, extract Alex's age. - Use indexing to solve this task.
Solution
99
1
2
3
4
5
6
7
8
9
10
11
people = (('Alex', 23, 178), ('Noah', 34, 189), ('Peter', 29, 175), ('John', 41, 185), ('Michelle', 35, 165))
# Write your code here
peters_info = people[2]
johns_height = people[3][2]
alexs_age = people[0][1]
# Testing
print(f"Full info about peter: {peters_info};\nInfo about John's height: {johns_height};\nInfo about Alex's age: {alexs_age}.")
Everything was clear?
Thanks for your feedback!
Section 4. Chapter 10
99
1
2
3
4
5
6
7
8
9
10
11
people = (('Alex', 23, 178), ('Noah', 34, 189), ('Peter', 29, 175), ('John', 41, 185), ('Michelle', 35, 165))
# Write your code here
peters_info = ___
johns_height = ___
alexs_age = ___
# Testing
print(f"Full info about peter: {peters_info};\nInfo about John's height: {johns_height};\nInfo about Alex's age: {alexs_age}.")
Ask AI
Ask anything or try one of the suggested questions to begin our chat