views:

104

answers:

2

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.

+4  A: 

add a colon after the else so that it looks like else:. and pick up a good tutorial ;)

aaronasterling
Aww...I thought about it and checked if this syntax is required, however I still missed to notice it!! Thanks.
Harpreet
+2  A: 

Looks like you need a ':' after "else".

Chris