开发者

INVALID SYNTAX ERROR for 'else' statement in python [closed]

开发者 https://www.devze.com 2023-01-18 07:33 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved开发者_运维知识库 in a way less likely to help future readers.

Closed 2 years ago.

Improve this question

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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消