请大佬帮忙 谢谢
x = int(input())y = int(input())
p = min(x,y)
q = max(x,y)
a=[]
for i in range(p):
for a in range(q):
s = str(i * a)
a.append(s)
报错:
a.append(str(s))
AttributeError: 'int' object has no attribute 'append' 第二个for循环,改成for j in range(q):
然后s改成s = str(i * j) 列表改个名字
和循环的对象重名了
x = int(input())
y = int(input())
p = min(x,y)
q = max(x,y)
clist=[]
for i in range(p):
for a in range(q):
s = str(i * a)
clist.append(s) a=[]
for i in range(p):
for a in range(q):
s = str(i * a)
a.append(s)
你上面的 a 列表,与 for 循环中的 a 变量同名了
a=[]
for a in range(q): x = int(input())
y = int(input())
p = min(x,y)
q = max(x,y)
a=[]# 这里定义了a
for i in range(p):
for a in range(q):# 这样重复用了a
s = str(i * a)
a.append(s) # 整数没有append方法
改成这样就好了:
x = int(input())
y = int(input())
p = min(x,y)
q = max(x,y)
a=[]
for i in range(p):
for x in range(q):# 随便拿个没有重复的值替代~OK了
s = str(i * x)
a.append(s) 乱起变量名造成的严重后果 变量和列表重复名称
页:
[1]