Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

activity 3.3.1: tuple basics. import the namedtuple container from coll…

Question

activity
3.3.1: tuple basics.
import the namedtuple container from collections. then, define a named tuple called city with fields name, state, and population, in that order.
check here for example
1
2
3
4
5
6
7
8
9
10
your code goes here...
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}\)
jump to level 1.

Explanation:

Step1: Import namedtuple from collections

from collections import namedtuple

Step2: Define City namedtuple

City = namedtuple('City', ['name', 'state', 'population'])

Step3: Get city name input

city_name = input()

Step4: Get state input

state_located = input()

Step5: Get population input (convert to int)

population_count = int(input())

Step6: Create City object

city_data = City(city_name, state_located, population_count)

Step7: Print formatted result

print(f"City name: {city_data.name}, State: {city_data.state}, Population: {city_data.population}")

Answer:

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}")