Q15.改变对象与绑定
P54:Univs和Univs1被绑定到不同的对象的原理不是很清楚。
bigjing:
Univs = [Techs, Ivys]
Univs1 = [['MIT', 'Caltech'], ['Harvard', 'Yale', 'Brown']]
Univs绑定的是含有Techs和Ivys的列表。
Univs1绑定的是含有['MIT', 'Caltech']和['Harvard', 'Yale', 'Brown']的列表
所以Univs和Univs1被绑定到不同的对象
书上有解释【Univs中的元素不是Techs和Ivys绑定的列表的复制,而是这些列表本身】
Q16.遇到TypeError: ‘int’ object is not callable报错该如何处理?
正在做week2:Exercise: gcd iter
检查了自己的代码感觉逻辑没有什么错误
但是一运行就显示TypeError: 'int' object is not callable的报错
求问该如何更改解决,代码如下:
def gcdIter(a, b):
'''
a, b: positive integers
returns: a positive integer, the greatest common divisor of a & b.
'''
i = min(a, b)
while i > 0:
if a % i == 0 and b % i == 0:
return i
else:
i -= 1
bigjing:
用python2和python3都运行了一下,并没有问题出现
Q17. 测试途径分析
# 分析week4-7 Ex4:
def union(set1, set2):
"""
set1 and set2 are collections of objects, each of which might be empty.
Each set has no duplicates within itself, but there may be objects that
are in both sets. Objects are assumed to be of the same type.
This function returns one set containing all elements from
both input sets, but with no duplicates.
"""
if len(set1) == 0:
return set2
elif set1[0] in set2:
return union(set1[