Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Retrieving Information from Nested Tuple | Other Data Types in Python
Introduction to Python

book
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:

NameAgeHeight
Alex23178
Noah34189
Peter29175
John41185
Michelle35165

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

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?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 10
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

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt