教材:《Python编程 从入门到实践》
6-2:喜欢的数字
#6-2 favorite number
d = {"Alice": 1, "Bob": 2, "Carol": 3, "Dennis": 4, "Edward": 5}
for i in d:
print(i + "'s favorite number is " + str(d[i]))
输出:
Alice's favorite number is 1
Bob's favorite number is 2
Carol's favorite number is 3
Dennis's favorite number is 4
Edward's favorite number is 5
6-3:词汇表
#6-3 vocabulary
d = {
'variable':
'a storage location (identified by a memory address) paired with an associated symbolic name (an identifier), which contains some known or unknown quantity of information referred to as a value',
'loop':
'a sequence of statements which is specified once but which may be carried out several times in succession',
'class':
'an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods)',
'debugging':
'the process of finding and resolving defects or problems within a computer program that prevent correct operation of computer software or a system',
'sorting':
'any process of arranging items systematically'
}
for i in d:
print(i + ': ' + d[i] + '.')
输出:
variable: a storage location (identified by a memory address) paired with an associated symbolic name (an identifier), which contains some known or unknown quantity of information referred to as a value.
loop: a sequence of statements which is specified once but which may be carried out several times in succession.
class: an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods).
debugging: the process of finding and resolving defects or problems within a computer program that prevent correct operation of computer software or a system.
sorting: any process of arranging items systematically.
6-10:喜欢的数字
#6-10 favorite numbers
d = {
"Alice": [1, 2],
"Bob": [3, 4],
"Carol": [5, 6],
"Dennis": [7, 8],
"Edward": [9, 0]
}
for i in d:
print(i + "'s favorite numbers are " + str(d[i]))
输出:
Alice's favorite numbers are [1, 2]
Bob's favorite numbers are [3, 4]
Carol's favorite numbers are [5, 6]
Dennis's favorite numbers are [7, 8]
Edward's favorite numbers are [9, 0]