python编程从入门到实践(第二版)第六章习题答案6.7-6.11

6.7

friend_0 = {'first_name':'hao','last_name':'zeng yao','age':22,'city':'He zhe'}
friend_1 = {'first_name':'zhang','last_name':'yu','age':22,'city':'Ji nan'}
friend_2 = {'first_name':'yuan','last_name':'hao','age':21,'city':'Ji nan'}

friends = [friend_0,friend_1,friend_2]
for friend in friends:
    print(friend)

6.8

pet_0 = {'type': 'dog','The host name': 'Tom'}
pet_1 = {'type': 'cat','The host name': 'john'}
pet_2 = {'type': 'pig','The host name': 'A'}

pets = [pet_0, pet_1, pet_2]
for pet in pets:
    print(pet)

 6.9

favorite_places = {
    'alice': ['Hang zhou','Bei jing','Qing dao'],
    'david': ['Macau'],
    'carolina': ['Tai wan','Hong kong'],
    }
for name,places in favorite_places.items():
    print(f"\n{name.title()}'s favorite places are:")
    for place in places:
        print(f"\t{place.title()}")

6.10
favorite_numbers = {
    'Jonaka':['8', '2', '9',],
    'Jaide':['6', '7',],
    'Tressa':['4','3',],
    'Paolina':['5'],
    'Urbana':['10'],
    }

for name,numbers in favorite_numbers.items():
    print(f"{name.title()}'s favorite numbers are:")
    for number in numbers:
        print(f"\t{number}")

6.11
cities = {
    'Paris': {
        'country': 'French',
        'population': '67813396',
        'fact': 'environmental pollution'
        },
    
    'New York':{
        'country': 'The United States',
        'population': '333 million',
        'fact': 'epidemic',
        },
    
    'Macau':{
        'country': 'China',
        'population': '14 million',
        'fact': 'epidemic',
        },
    }

for city,informations in cities.items():
    print(f"\nCity: {city}")
    country = f"{informations['country']}"
    population = f"{informations['population']}"
    fact = informations['fact']
    
    print(f"\tCountry: {country}")
    print(f"\tPopulation: {population}")
    print(f"\tFact:{fact}")

你可能感兴趣的:(python)