โดย fuyuppe » 18/08/2019 3:20 pm
ภาษา Python
ต้องการผลรวมของ list ตัวอย่าง [3,4,4] = 48
def partition(number):
answer = set()
answer.add((number, ))
for x in range(1, number):
for y in partition(number - x):
answer.add(tuple(sorted((x, ) + y)))
return answer
u = int(4)
a = partition(u)
b = list(a)
c = len(b)
product = 1
for i in range(c):
# product *= b บรรทัดที่เป็นปัญหา
print(b)
error คือ TypeError: can't multiply sequence by non-int of type 'tuple'
ขอบคุณครับ
ภาษา Python
ต้องการผลรวมของ list ตัวอย่าง [3,4,4] = 48
def partition(number):
answer = set()
answer.add((number, ))
for x in range(1, number):
for y in partition(number - x):
answer.add(tuple(sorted((x, ) + y)))
return answer
u = int(4)
a = partition(u)
b = list(a)
c = len(b)
product = 1
for i in range(c):
# product *= b[i] บรรทัดที่เป็นปัญหา
print(b[i])
error คือ TypeError: can't multiply sequence by non-int of type 'tuple'
ขอบคุณครับ