สอบถามเกี่ยวกับการ บวก ลบ ใน Tuple ทำยังไงครับ ภาษา Python

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: สอบถามเกี่ยวกับการ บวก ลบ ใน Tuple ทำยังไงครับ ภาษา Python

สอบถามเกี่ยวกับการ บวก ลบ ใน Tuple ทำยังไงครับ ภาษา Python

โดย 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'

ขอบคุณครับ

ข้างบน