Python code

View previous topic View next topic Go down

Python code

Post by Pibor on 26/10/2013, 1:02 am

generating a random list of 30 integers and applying the insertion sorting.

This is what I have, but only prints 1 integer:

Code:

import random

N = 30 #defining number of elements
s = [] #defining list of elements

s.append ( int ( random.uniform ( 0, 30 ) ) )

def sort_numbers(s):
    for i in range(1, N, len(s)):

        # let's see what values i takes on
        print ('i = '), i

        val = s[i]
        j = i - 1
        while (j >= 0) and (s[j] > val):
            s[j+1] = s[j]
            j = j - 1
        s[j+1] = val
print(s)
I also would like to know how to do shell sorting and quick sorting as well by generating a random list of 30 integers

Pibor
Tier 4 (500 posts)
Tier 4 (500 posts)


Back to top Go down

Re: Python code

Post by Divine on 26/10/2013, 10:00 am

Not sure if it'll help you, but Snow, one of our former Generals, is very experienced with Python and has a lot of video tutorials about it: http://www.youtube.com/user/sentdex

You could perhaps try to contact him on IRC, his name is Snow-Merchz and you can find him in the #Merchz channel.

Best of luck Smile
avatar
Divine
Administrator
Administrator


http://merchz.com/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum