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

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น ภาษา Java ภาษา Python

Moderator: mindphp, ผู้ดูแลกระดาน

fuyuppe
PHP Newbie
PHP Newbie
โพสต์: 1
ลงทะเบียนเมื่อ: 18/08/2019 3:12 pm

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

โพสต์ที่ยังไม่ได้อ่าน โดย fuyuppe »

ภาษา 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'

ขอบคุณครับ
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 44