Posted on 16th September 2024|573 views
How to resolve the syntax error: bad input?
I am trying to print the sum of even numbers, but I am seeing this error called syntax error: bad input why? Here is my code
num = range(1,40)
num[0]=1 num[1]=2
for j in range(2,41):
num[j]=num[j-1]+num[j-2]
total=0
for j in range(0,41):
print num[j]
if num[j]%2==0:
total=total+num[j]
else:
num[j]=num[j+1]
Posted on 16th September 2024| views
I think the mistake is in this part
if num[j]%2==0:
total=total+num[j]
else:
num[j]=num[j+1]
In python alignment is very important try to change your code like this
if num[j]%2==0:
total=total+num[j]
else:
num[j]=num[j+1]