There is an error in my code that i cannot understand

why is the list not taking in elements that i have provided.

the code works fine in format
total =0
a = (8,17,28,-100,)
for ele in range(0,len(a)):
total = total + a[ele]
if total > 0:
print(total)

but breaks in format
total =0
a = []
n = int(input("Enter no of elements: "))
for i in range(0,n):
ele1 = float(input())

a.append(ele)

print(a)

for ele in range(0,len(a)):
total = total + a[ele]
if total > 0:
print(total)

Hi @dikshant9sharma

Overhere it should be a.append(ele1) instead of a.append(ele). Overhere you are storing the input value in ele1 variable and appending the value stored in ele varaible thats why your list wasn’t able to store the input that you provided.

Hope this might helps :slightly_smiling_face:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.