【HW】 第六章作业 2018.3.21
2018-03-21 23:48
274 查看
Python代码:#Chapter 6 by szh 2018.3.21
print("\n6.1")
person1 = {'first_name':'Alan', 'last_name':'Turing', 'age':28, 'city':'London'}
for k in person1.keys():
print(k, ':', person1[k])
print("\n6.2")
favorite_num = {'Alice':3, 'Bob':7, 'Jack':11, 'John':13, 'Eric': 17}
for k, v in favorite_num.items():
print(k, ':', v)
print("\n6.3")
key_words = {'&':'and', '|':'or', '^':'xor', '~':'not'}
for k, v in key_words.items():
print(k + "\n\t" + v)
print("\n6.4")
for k, v in key_words.items():
print(k + "\n\t" + v)
key_words['int'] = 'Integer'
key_words['float'] = 'Single-precision floating-point'
key_words['double'] = 'Double-precision floating-point'
key_words['char'] = 'character'
for k, v in key_words.items():
print(k + "\n\t" + v)
print("\n6.5")
rivers = {'nile':'Egypt', 'Amazon':'Brazil', 'Yangzi River':'China'}
for k, v in rivers.items():
print("The " + k + " runs through " + v + ".")
for k in rivers.keys():
print(k)
for v in rivers.values():
print(v)
print("\n6.7")
person2 = {'first_name':'Albert', 'last_name':'Einstein', 'age':58, 'city':'Washington'}
people = [person1, person2]
for person in people:
for k in person.keys():
print(k, ':', person[k])
print("\n6.8")
cat = {'Doli':'Alice'}
dog = {'hero':'Bob'}
rabbit = {'milk':'Jack'}
pets = [cat, dog, rabbit]
for pet in pets:
for k, v in pet.items():
print(k + ':' + v)
print("\n6.9")
fp1 = {'Alice':['London', 'Beijing', 'Zhuhai']}
fp2 = {'Bob': ['Paris', 'Washington']}
fp3 = {'Eric': ['Moscow', 'Tokyo']}
favorite_places = [fp1, fp2 ,fp3]
for favorite_place in favorite_places:
for k, v in favorite_place.items():
print(k + ":", end = '')
for place in v:
print(place + ' ', end = '')
print()
输出结果:6.1
first_name : Alan
last_name : Turing
age : 28
city : London
6.2
Alice : 3
Bob : 7
Jack : 11
John : 13
Eric : 17
6.3
&
and
|
or
^
xor
~
not
6.4
&
and
|
or
^
xor
~
not
&
and
|
or
^
xor
~
not
int
Integer
float
Single-precision floating-point
double
Double-precision floating-point
char
character
6.5
The nile runs through Egypt.
The Amazon runs through Brazil.
The Yangzi River runs through China.
nile
Amazon
Yangzi River
Egypt
Brazil
China
6.7
first_name : Alan
last_name : Turing
age : 28
city : London
first_name : Albert
last_name : Einstein
age : 58
city : Washington
6.8
Doli:Alice
hero:Bob
milk:Jack
6.9
Alice:London Beijing Zhuhai
Bob:Paris Washington
Eric:Moscow Tokyo
输出结果:
print("\n6.1")
person1 = {'first_name':'Alan', 'last_name':'Turing', 'age':28, 'city':'London'}
for k in person1.keys():
print(k, ':', person1[k])
print("\n6.2")
favorite_num = {'Alice':3, 'Bob':7, 'Jack':11, 'John':13, 'Eric': 17}
for k, v in favorite_num.items():
print(k, ':', v)
print("\n6.3")
key_words = {'&':'and', '|':'or', '^':'xor', '~':'not'}
for k, v in key_words.items():
print(k + "\n\t" + v)
print("\n6.4")
for k, v in key_words.items():
print(k + "\n\t" + v)
key_words['int'] = 'Integer'
key_words['float'] = 'Single-precision floating-point'
key_words['double'] = 'Double-precision floating-point'
key_words['char'] = 'character'
for k, v in key_words.items():
print(k + "\n\t" + v)
print("\n6.5")
rivers = {'nile':'Egypt', 'Amazon':'Brazil', 'Yangzi River':'China'}
for k, v in rivers.items():
print("The " + k + " runs through " + v + ".")
for k in rivers.keys():
print(k)
for v in rivers.values():
print(v)
print("\n6.7")
person2 = {'first_name':'Albert', 'last_name':'Einstein', 'age':58, 'city':'Washington'}
people = [person1, person2]
for person in people:
for k in person.keys():
print(k, ':', person[k])
print("\n6.8")
cat = {'Doli':'Alice'}
dog = {'hero':'Bob'}
rabbit = {'milk':'Jack'}
pets = [cat, dog, rabbit]
for pet in pets:
for k, v in pet.items():
print(k + ':' + v)
print("\n6.9")
fp1 = {'Alice':['London', 'Beijing', 'Zhuhai']}
fp2 = {'Bob': ['Paris', 'Washington']}
fp3 = {'Eric': ['Moscow', 'Tokyo']}
favorite_places = [fp1, fp2 ,fp3]
for favorite_place in favorite_places:
for k, v in favorite_place.items():
print(k + ":", end = '')
for place in v:
print(place + ' ', end = '')
print()
输出结果:6.1
first_name : Alan
last_name : Turing
age : 28
city : London
6.2
Alice : 3
Bob : 7
Jack : 11
John : 13
Eric : 17
6.3
&
and
|
or
^
xor
~
not
6.4
&
and
|
or
^
xor
~
not
&
and
|
or
^
xor
~
not
int
Integer
float
Single-precision floating-point
double
Double-precision floating-point
char
character
6.5
The nile runs through Egypt.
The Amazon runs through Brazil.
The Yangzi River runs through China.
nile
Amazon
Yangzi River
Egypt
Brazil
China
6.7
first_name : Alan
last_name : Turing
age : 28
city : London
first_name : Albert
last_name : Einstein
age : 58
city : Washington
6.8
Doli:Alice
hero:Bob
milk:Jack
6.9
Alice:London Beijing Zhuhai
Bob:Paris Washington
Eric:Moscow Tokyo
输出结果:
相关文章推荐
- 《Java数据结构和算法》第二版 Robert lafore 编程作业 第六章
- 作业7——第六章习题选做
- JavaScript第六章课后作业
- 第六章实验作业
- The C++ Programming Language 第六章 作业
- 第六章作业:动物声音模拟器(接口)
- 第六章作业
- 第六章作业
- 第六章作业
- 第六章作业
- 第六章作业2
- 现代软件工程第六章作业
- 高级编程基础第六章作业--字典
- 第六章作业
- 王爽汇编 第六章包含多个段的程序 作业
- 20135327郭皓 20135329李海空第六章作业 6.30 6.37
- 第六章作业
- 作业 1 熟悉C语言编程环境 第六章
- 第六章----家庭作业
- 【HW】第四章作业 2018.3.14