Python编程:从入门到实践的动手试一试练习答案(第六章)

以下内容非标准答案,是我个人练习内容,仅供参考:

如有不准确,希望指出

# ~ #6-1
user_information = {
    
    
    'first_name': '王',
    'last_name': '小',
    'age': 18,
    'city': '中国上海'
    }
    
print('姓: ' + user_information['first_name'])
print('名: ' + user_information['last_name'])
print('年龄: ' + str(user_information['age']))
print('城市: ' + user_information['city'])
# ~ #6-2
like_nums = {
    
    
    'name_1': '王小',
    'like_num_1': 18,
    'name_2': '陈四',
    'like_num_2': 13,
    'name_3': '李维',
    'like_num_3': 6,
    'name_4': '龙五',
    'like_num_4': 9
    }

print(
    like_nums['name_1'] + '喜欢的数字是' + str(like_nums['like_num_1'])
    )
print(
    like_nums['name_2'] + '喜欢的数字是' + str(like_nums['like_num_2'])
    )
print(
    like_nums['name_3'] + '喜欢的数字是' + str(like_nums['like_num_3'])
    )
print(
    like_nums['name_4'] + '喜欢的数字是' + str(like_nums['like_num_4'])
    )
# ~ #6-3
python = {
    
    
    'python_1': 'print',
    'python_1_1': '打印结果或输出结果',
    
    'python_2': 'append',
    'python_2_2': '在列表或者元组中添加元素',
    
    'python_3': 'str',
    'python_3_3': '转换元素为字符',
    
    'python_4': 'int',
    'python_4_4': '转换为整数',
    
    'python_5': 'range',
    'python_5_5': '生成数字表列表',
    }

print('python词汇: ' + python['python_1'] + 
    '\n含义: ' + python['python_1_1'] +
    
    '\npython词汇: ' + python['python_2'] + 
    '\n含义: ' + python['python_2_2'] +
    
    '\npython词汇: ' + python['python_3'] + 
    '\n含义: ' + python['python_3_3'] +
    
    '\npython词汇: ' + python['python_4'] + 
    '\n含义: ' + python['python_4_4'] +
    
    '\npython词汇: ' + python['python_5'] + 
    '\n含义: ' + python['python_5_5']
    )
# ~ #6-4
python = {
    
    
    'print': '打印结果或输出结果',
    'append': '在列表或者元组中添加元素',
    'str': '转换元素为字符',
    'int': '转换为整数',
    'range': '生成数字表列表',
    'title': '首字母大写',
    'del': '删除内容',
    'zip' : '合并列表数据',
    'teyp' : '显示类型',
    '%': '算数符号,除法计算余数'
    }
    
for python, value in python.items():
    print('\n'+ python.title())
    print(value)
# ~ #6-5
river = {
    
    
    '尼罗河': '埃及',
    '亚马逊': '巴西',
    '长江': '中国'
    }

for river,nation in river.items():
    print('\n世界三大运河的' + river + '流经' + nation + '。')
# ~ #6-6
favorite_languages = {
    
    
    'jen': 'python',
    'sarah': 'c',
    'edward': 'ruby',
    'phil': 'pythone'
	}

names = [
    'jen', 'sarah', 'edward',
    'phil', 'agnes', 'charles'
	]

for name in names:
    if name in favorite_languages.keys():
        print(name + '谢谢您帮助调查')
    else:
        print(name + '请立即参加调查')
# ~ #6-7
user_1 = {
    
    
    'first_name': '王',
    'last_name': '小',
    'age': 18,
    'city': '上海'
    }
user_2 = {
    
    
    'first_name': '丘',
    'last_name': '金',
    'age': 16,
    'city': '东北'
    }
user_3 = {
    
    
    'first_name': '朗姆',
    'last_name': '苛杂',
    'age': 19,
    'city': '青海'
    }
    
peoples = [user_1,user_2,user_3]

for people in peoples:
    print(people)
# ~ #6-8
小球 = {
    
    
    '品种': '金毛',
    '主人': '金星'
    }

哈喽 = {
    
    
    '品种': '萨摩',
    '主人': '路十三'
    }

口水 = {
    
    
    '品种': '英国斗牛犬',
    '主人': '冉尘尘'
    }
        
pets = [小球,哈喽,口水]

for pet in pets:
    print(pet)
# ~ #6-9
favorite_places = {
    
    
    'agnes': '中国大理,日本大阪',
    'alice': '美国拉斯维加斯,埃及,中国拉萨',
    'Emma': '上海青浦,法国巴黎',
    'Juliette': '英国伦敦,日本神奈川,法国尼斯',
    }
    
for name,place in favorite_places.items():
    print(name + '最喜欢去的国家和地方是: ' + place)
# ~ #6-10
like_nums = {
    
    
    '王小': [18,27,19],
    '陈四': [13,12,9],
    '李维': [6,7,17],
    '龙五': [9,16,18]
    }
for name,num in like_nums.items():
    print(name + '最喜欢的数字是:' + str(num))   
# ~ #6-11
cities = {
    
    
    '上海':{
    
    
        'country': '中国',
        'population': '2428万',
        'fact': '国务院批复确定的中国国际经济、金融、贸易、航运、科技创新中心。',
        },
    '纽约':{
    
    
        'country': '美国',
        'population': '851万',
        'fact': '美国第一大城市及第一大港口。',
        },
    '东京':{
    
    
        'country': '日本',
        'population': '1350万',
        'fact': '全球规模最大的都会区之一,亦为日本最大的城市。',
        }
    }
for city,info in cities.items():
    country = info['country']
    population = info['population']
    fact = info['fact']
    
    print('\n城市: ' + city + 
        '\n国家:' + country +
        '\n人口数量: ' + population +
        '\n' + city + '是' + fact
        )
# ~ #6-12

猜你喜欢

转载自blog.csdn.net/chenchao0932/article/details/105101976