日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python第二版第六章课后答案_《Python编程》第六章部分课后练习题

發布時間:2024/9/19 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python第二版第六章课后答案_《Python编程》第六章部分课后练习题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#6-3 詞匯表:

代碼:#6-3 詞匯表

dic = {

'': 'Vectors are sequence containers representing arrays that can change in size.',

'': 'Stacks are a type of container adaptor, specifically designed to operate in '

'a LIFO context (last-in first-out), where elements are inserted and extracted only from one end of the container.',

'': 'Maps are associative containers that store elements formed by a combination of a '

'key value and a mapped value, following a specific order.',

'': 'Sets are containers that store unique elements following a specific order.',

'': 'queues are a type of container adaptor, specifically designed to operate in a'

' FIFO context (first-in first-out), where elements are inserted into one end of the container and extracted from the other.',

}

for key, value in dic.items():

print(key, ':', value, '\n')

輸出: : Vectors are sequence containers representing arrays that can change in size.

: Stacks are a type of container adaptor, specifically designed to operate in a LI

FO context (last-in first-out), where elements are inserted and extracted only from one en

d of the container.

: Maps are associative containers that store elements formed by a combination of a k

ey value and a mapped value, following a specific order.

: Sets are containers that store unique elements following a specific order.

: queues are a type of container adaptor, specifically designed to operate in a FI

FO context (first-in first-out), where elements are inserted into one end of the container

and extracted from the other.

#6-5 河流:

代碼:#6-5 河流

rivers = {

'nile': 'egypt',

'amazon': 'brazil',

'thames': 'england',

}

for river, country in rivers.items():

message = 'The ' + river.title() + ' runs through ' + country.title()

print(message)

print('\n')

for river in rivers.keys():

print(river.title())

print('\n')

for country in rivers.values():

print(country.title())

輸出:The Nile runs through Egypt

The Amazon runs through Brazil

The Thames runs through England

Nile

Amazon

Thames

Egypt

Brazil

England

#6-8 寵物:

代碼:#6-8 寵物

dogs = {

'Affenpinscher': 'Smiths',

'Afghan Hound': 'Bob',

'Aidi': 'Peter',

}

cats = {

'Bobtail': 'Lory',

'American Shorthair': 'Peter',

'Bombay': 'Tom',

}

birds = {

'Canary': 'Lory',

'Budgy': 'Tom',

'Cockatiel': 'Bob',

}

pets = [dogs, cats, birds]

for pet in pets:

for name, owner in pet.items():

message = owner + ' has '

if name[0] in 'AOEIU':

message += 'an '

else:

message += 'a '

message += name

print(message)

輸出:Smiths has an Affenpinscher

Bob has an Afghan Hound

Peter has an Aidi

Lory has a Bobtail

Peter has an American Shorthair

Tom has a Bombay

Lory has a Canary

Tom has a Budgy

Bob has a Cockatiel

#6-11 城市:

代碼:#6-11 城市

Los_Angeles = {

'country': 'USA',

'population': '3,971,883',

'fact': 'It is home to the Wilshire Grand Center, California’s tallest Building.',

}

Guangzhou = {

'country': 'China',

'population': '13,501,100',

'fact': '2008 The 49th World Table Tennis Championships.',

}

Tokyo = {

'country': 'Japan',

'population': '9,262,046',

'fact': 'In 2016, it was to be replaced by the New National Stadium.',

}

cities = {

'Los Angeles': Los_Angeles,

'Guangzhou': Guangzhou,

'Tokyo': Tokyo,

}

for city, dic in cities.items():

message = '\n' + city + ':'

print(message)

for key, value in dic.items():

message = ' ' + key + ': ' + value

print(message)

輸出:Los Angeles:

country: USA

population: 3,971,883

fact: It is home to the Wilshire Grand Center, California’s tallest Building.

Guangzhou:

country: China

population: 13,501,100

fact: 2008 The 49th World Table Tennis Championships.

Tokyo:

country: Japan

population: 9,262,046

fact: In 2016, it was to be replaced by the New National Stadium.

總結

以上是生活随笔為你收集整理的python第二版第六章课后答案_《Python编程》第六章部分课后练习题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。