第六章作业

"""6.1 人"""
friend = {'first_name': 'LI', 'last_name': 'Xiaoming', 'age': 19, 'city': 'Guangzhou'}
print(friend['first_name'] + ' ' + friend['last_name'])
print(friend['age'])
print(friend['city'])




"""6.2 喜欢的数字"""
favorite_number = {'Bob': 7, 'Alice': 6, 'Amy': 8, 'Tom': 24, 'David': '36'}
print("Bob; " + str(favorite_number['Bob']))
print("Alice; " + str(favorite_number['Alice']))
print("Amy; " + str(favorite_number['Amy']))
print("Tom; " + str(favorite_number['Tom']))
print("David; " + str(favorite_number['David']))




"""6.3 词汇表"""
dictionary = {
'print': 'display some words',
'insert': 'insert an element into a list',
'append': 'insert an element at the end of a list',
'pop': 'delect the last element of a list',
'sort': 'sort a list',
}


print("print: " + dictionary['print'])
print("insert: " + dictionary['insert'])
print("append: " + dictionary['append'])
print("pop: " + dictionary['pop'])
print("sort: " + dictionary['sort'])




"""6.4 词汇表2"""
dictionary = {
'print': 'display some words',
'insert': 'insert an element into a list',
'append': 'insert an element at the end of a list',
'pop': 'delect the last element of a list',
'sort': 'sort a list',
}


dictionary['in'] = 'to find whether an element is in a list'
dictionary['if'] = 'a word used to judge'
dictionary['input'] = 'a function name, to input something to the computer'
dictionary['int'] = 'a function name, to input a number'
dictionary['while'] = 'a word use to begin a loop'


for key, value in dictionary.items():
print(key + ": " + value)




"""6.5 河流"""
rivers = {
'Pearl': 'China',
'Mississippi': 'America',
'Lena': 'Russia'
}


for key, value in rivers.items():
print("The " + key + " runs through " + value + ".")
print("\n", end = '')
for name in rivers.keys():
print(name)
print("\n", end = '')
for country in rivers.values():
print(country)


"""6.6 调查"""
favorite_languages = {
'jen': 'python',
'sarah': 'c',
'edward': 'ruby',
'phil': 'python',
}
people = ['phil', 'cindy', 'alicy', 'sarah', 'david']
for name in people:
if name in favorite_languages.keys():
print(name.title() + ", thank you for your participation!")
else:
print(name.title() + ", I would like to invite you to take part in the survey.")




"""6.7 人"""
friend = {'first_name': 'LI', 'last_name': 'Xiaoming', 'age': 19, 'city': 'Guangzhou'}
classmate = {'first_name': 'zhang', 'last_name': 'San', 'age': 20, 'city': 'Guangzhou'}
partner = {'first_name': 'Wang', 'last_name': 'Wu', 'age': 18, 'city': 'Guangzhou'}
person = [friend, classmate, partner]


for role in person:
for key, value in role.items():
print(key + ": " + str(value))
print("\n", end = '')




"""6.8 宠物"""
wangcai = {'type': 'dog', 'master': 'zhou dai'}
pink = {'tupe': 'pig', 'master': 'zhu yan'}
miao = {'type': 'cat', 'master': 'xiao meng'}
pets = [wangcai, pink, miao]
for name in pets:
print(name)




"""6.9 喜欢的地方"""
favorite_places = {
'Bob': ['Pairs','New York'],
'Alice': ['Tokyo', 'Seoul'],
'Liming': ['Guangzhou', 'Dali', 'Shanghai']
}
for key, value in favorite_places.items():
print(key + ": ", end = '')
for place in value:
print(place + " ", end = '')
print("\n", end = '')




"""6.10 喜欢的数字"""
favorite_number = {
'Bob': [7, 28, 99, 888],
'Alice': [6, 2333],
'Amy': [4, 2],
'Tom': [24, 16, 28],
'David': [36, 88, 250],
}
for key, value in favorite_number.items():
print(key + ": ", end = '')
for number in value:
print(str(number) + " ", end = '')
print("\n", end = '')

猜你喜欢

转载自blog.csdn.net/ad_jadson/article/details/79669788