QUESTION IMAGE
Question
jump to level 1
import the namedtuple container from collections. then, define a named tuple called city with fields: name, state, and population, in that order.
click here for example
1 city = namedtuple(city, name, state, population)
2
3 city_name = input()
4 state_name = input()
5 population_count = int(input())
6 city_data = city(city_name, state_located, population_count)
7 print(f\city name: {city_data.name}, state: {city_data.state}, population: {city_data.population}\)
8
9
10
check
next level
the import statement begins with the keyword \from\, followed by the collections library, the keyword \import\ and the namedtuple container.
calling the namedtuple constructor with \city\ as the first argument and
ame\, \state\, \population\ as the second argument creates a named tuple data type called city with fields: name, state, and population.
not all tests passed.
x 1: compare output
Step1: Add missing import statement
from collections import namedtuple
Step2: Fix typo in field name
Change 'poppulation' to 'population' in line 2
Step3: Correct namedtuple constructor call
Change city to City as the constructor name in line 2
Step4: Fix attribute access in print
Change .name, .state, .population to .name, .state, .population (matches corrected field name)
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
from collections import namedtuple
City = namedtuple('City', ['name', 'state', 'population'])
city_name = input()
state_located = input()
population_count = int(input())
city_data = City(city_name, state_located, population_count)
print(f"City name: {city_data.name}, State: {city_data.state}, Population: {city_data.population}")