Post

PythonPython

v
victoria mamidi

Posted on 28th February 2024|540 views

0
votes

Syntaxerror Bad Input

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]

 

Answers
P
Surya kumar

Posted on 28th February 2024

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]

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos