How to correct the Invalidsyntax Error in line 7? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to correct the Invalidsyntax Error in line 7?

I have a list and want to input a digit so that the output is the list's element on the respective position. The variable "word" is supposed to be that digit representing the position, starting from 1 up to len(list). Why is there an InvalidSyntaxError in line 7? 1 command=input() 2 word=input() 3 if command=='pos': 4 if word.isdigit(): 5 if 1<=int(word)<=len(list): 6 print('element on position',str(word),+':'+str(list(word-1)) 7 else: 8 print('Position',word,'out of range.') 9 else: 10 print('Error: Enter digit.') Thank You in advance!

22nd Oct 2020, 12:33 PM
Donut
Donut - avatar
2 Answers
+ 6
There is a missing closing bracket at line 7
22nd Oct 2020, 12:35 PM
Abhay
Abhay - avatar
+ 4
...and a comma in b/w str(word) and ':' (line 6)
22nd Oct 2020, 12:43 PM
777
777 - avatar