【发布时间】:2021-10-29 03:49:30
【问题描述】:
def foo(x, a, b, i, j):
k = j
ct = 0
while k > i-1:
if x[k] <= b and not (x[k] <= a):
ct = ct + 1
k = k - 1
return ct
x = (11,10,10,5,10,15,20,10,7,11)
y = [10000000000000000000]
m = 0
while m < 10000000000000000000:
y[m] = m
m = m +1
print(foo(x,8,18,3,6))
print(foo(x,10,20,0,9))
print(foo(x,8,18,6,3))
print(foo(x,20,10,0,9))
print(foo(x,6,7,8,8))
# Please be careful with typos for the output of the following lines!
print(foo(y,
111112222233333, # five 1's, then five 2's, then five 3's
999998888877777, # five 9's, then five 8's, then five 7's
222223333344444, # five 2's, then five 3's, then five 4's
905003340009900023))
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last) <ipython-input-17-d3d2cd54b367> in <module>()
14
15 while m < 10000000000000000000:
---> 16 y[m] = m
17 m = m +1
18
TypeError: 'int' object does not support item assignment
【问题讨论】:
-
你的标题和提供的内容不匹配
-
欢迎来到 Stack Overflow!请解释一下这段代码应该做什么——这会让你更容易理解你出错的地方。