Click here to Skip to main content
15,886,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
import math
for _ in range (int(input())):
     n = int(input())
     A = list(map(int, input().split()))
     final=[]
     for  i in range(len(A)):
         if i==len(A)-1:
             final=final.append(A)
         else:
             for p in range (i+1,len(A)+1):
                final.append(math.prod(A[i : p]))
     print(sum(final))


What I have tried:

Traceback (most recent call last):
File "C:\Users\user\OneDrive\Desktop\New folder\test.py", line 12, in <module>
print(sum(final))
TypeError: 'NoneType' object is not iterable

i don't why it is showing like this
Posted
Updated 23-Jul-22 21:16pm

If you don't understand an error message, google it: TypeError: 'NoneType' object is not iterable - Google Search[^]
Any of those links explains why you get it - now all you have to do is look at what you entered as data and then use the debugger to find out what exactly is going on.

Since we don't have any idea what you typed, we can't do any of that for you!
 
Share this answer
 
The following line may well cause problems:
Python
final=final.append(A)

Remove the "final=" thus:
Python
final.append(A)

Also you should add some print statements after each final.append statement, to see what the results are:
Python
print(F"{final=}")

That will give you some nice debug output.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900