ภาษา 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'
ขอบคุณครับ
สอบถามเกี่ยวกับการ บวก ลบ ใน Tuple ทำยังไงครับ ภาษา Python
Moderators: mindphp, ผู้ดูแลกระดาน
-
- PHP Newbie
- Posts: 1
- Joined: 18/08/2019 3:12 pm
-
- Similar Topics
- Replies
- Views
- Last post
-
- 0 Replies
- 502 Views
-
Last post by Patcharanan.0399
17/04/2018 10:50 am
-
- 0 Replies
- 555 Views
-
Last post by Dive Demo
02/02/2017 5:41 pm
-
- 0 Replies
- 523 Views
-
Last post by jirawoot
24/06/2019 5:50 pm
-
- 1 Replies
- 458 Views
-
Last post by Jom07
26/01/2018 5:19 pm
-
- 1 Replies
- 331 Views
-
Last post by md040
30/12/2016 10:18 am
-
-
ทำความรู้จักกับภาษา python (7) : ตัวแปรชนิด Tuple(ทูเปิล)
by dawthana » 28/12/2016 3:38 pm » in Python Knowledge - 7 Replies
- 722 Views
-
Last post by jirawoot
19/06/2019 3:02 pm
-
Who is online
Users browsing this forum: No registered users and 4 guests