To take part in discussions on talkSFU, please apply for membership (SFU email id required).

cmpt 120 help!

edited July 2008 in General
oh dear, ok so I'm having a lot of problems with Python programming. it's just not for me...but i'm trying my best!!

one question on my assignment is to create a recursive function that sorts the list from start to end.

this is the pseudocode that the prof sent to help out...
def selection_sort(lst, start, end):
if start >= end:
return
else:
swap smallest element from lst[start:end+1] into lst[start]
selection_sort(lst, start+1, end)
return


and this is what i have, which doesn't actually work
def selection_sort(lst, start, end):
\"\"\"
sort the list in-place

>>> selection_sort([4, 6, 2, 3, 1], 1, 5)
[1,2,3,4,6]
\"\"\"
if start >= end:
return 0

else: #if start <= end
for i in range(start-1, end+1):
#start finding the values that are less the first number in list
if lst[i] < lst[0]:
lst[0], lst[i] = lst[i] = lst[0]
#find the smallest value and put it at the front
elif lst[i-1] < lst[0]:
lst[0], lst[i-1] = lst[i-1], lst[0]
start = i
lst[start] = lst[i]

#find the largest value and put it at the end of the list
elif lst[i] > lst[end+1]:

selection_sort(lst, start+1, end)

lst[i], lst[end+1] = lst[end+1], lst[i]
#print lst[end-1]


print selection_sort([4,6,2,3,1], 1, 3)


anyone have knowledge of Python?? any help is appreciated!!

Comments

  • edited December 2006
    Nevermind, it's not necessary because i just handed in my assignment.

    man, this course is killing me. my brain just isn't wired to think like a programmer.
  • edited December 2006
    meesh said:
    Nevermind, it's not necessary because i just handed in my assignment.

    man, this course is killing me. my brain just isn't wired to think like a programmer.

    whoa. i was planning to take CMPT 120 next semester.

    looks killer. ......

    i don't have ANY knowledge of programming what so ever...

    think i'll be screwed :confused: :sad:
  • edited December 2006
    I think it depends on who's teaching it. Pearce hates object-oriented programming, but at the same time people have complained about aspects of his teaching style. Win some, lose some.

    I've heard OK things about Cukierman though.
  • edited December 2006
    Tinana said:
    whoa. i was planning to take CMPT 120 next semester.

    looks killer. ......

    i don't have ANY knowledge of programming what so ever...

    think i'll be screwed :confused: :sad:
    i didn't have any knowledge of programming either,it's really not necessary.

    im just not spending nearly enough time on this class...
    it's not a prerequisite for me, it was just out of interest and curiosity.
  • edited June 2008
    I will give a hint to anyone taking this class. If you final assignment is a robot who walks around a maze looking for a coin then there are two ways to do this.

    The slow way:
    You have your robot walk along the walls in a clockwise direction, if it hits an obstacle have it take one step to the left. After every step see if the robot can see it and go to it, otherwise take another step.

    The fast way:
    Have your robot take a step in a random direction, eventually you will find your coin.
  • edited June 2008
    If you're going to cheat by asking us, you might as well get the answer faster.
    http://www.google.ca/search?q=python+selection+sort
    You can probably find the answer to all your first year programming questions on Google. Although, I wouldn't recommend it for obvious reasons.
    NukeChem;3963 said:
    I think it depends on who's teaching it. Pearce hates object-oriented programming, but at the same time people have complained about aspects of his teaching style. Win some, lose some.

    I've heard OK things about Cukierman though.
    A prof that hates object-oriented programming? He shouldn't be teaching programming then. Unless he's talking about pure OOP.

    JayDub, your first algorithm doesn't sound like it'd work. At least not without a few more conditions.
  • edited June 2008
    Of course my first one won't work I am not going to outright tell them the answer, it is just something to get them started on.

    Then again I never did 120, I skipped right to 126.
  • edited July 2008
    Lol...if you're trying to sound special, you really aren't. Shouldn't be majoring in comp sci if you didn't. Even 126 was a horrible joke. Same with 212.
  • edited July 2008
    I went through 120/125 only because 126 wasn't offered in surrey :(
  • edited July 2008
    What's wrong with doing cmpt-120?
  • edited July 2008
    120 is just way too easy and slow for anyone who already has some programming knowledge, regardless of how minimal
  • edited July 2008
    EricJ;32930 said:
    120 is just way too easy and slow for anyone who already has some programming knowledge, regardless of how minimal
    There's actually a fairly decent test on the CS website to see which one you should take. You can find it here.

    Phil
  • edited July 2008
    PhilB;33016 said:
    There's actually a fairly decent test on the CS website to see which one you should take. You can find it here.

    Phil
    Yeah, I took the test and did reasonably well, then noticed SFU Surrey didn't have 126 so I figured 120 wouldn't hurt. It was pretty slow and boring though
  • edited July 2008
    Comp sci didn't pick up until 3rd year.....or fourth? These 400+ courses are getting pretty tough anyways. Lots of fun maths :)

Leave a Comment