TAGS :Viewed: 14 - Published at: a few seconds ago
[ INVALID SYNTAX ERROR for 'else' statement in python ]
I am trying to write a quicksort program in python, however I'm getting an invalid syntax error at else statement
in the second last line below:
import random
n=int(raw_input("Enter the size of the list: ")) # size of the list
intlist = [0]*n
for num in range(n):
intlist[num]=random.randint(0,10*n)
pivot=random.choice(intlist)
list_1=[] # list of elements smaller than pivot
list_2=[] # list of elements greater than pivot
for num in range(n):
if num<=pivot:
list_1.append(num)
else
list_2.append(num)
This is not a complete program as I am still writing.
Answer 1
add a colon after the else
so that it looks like else:
. and pick up a good tutorial ;)
Answer 2
Looks like you need a ':' after "else".