Index
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Python code

2 posters

Go down

Python code Empty Python code

Post by Pibor 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

Python code Empty Re: Python code

Post by Divine 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: https://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
Divine
Divine
Administrator
Administrator


http://merchz.com/

Back to top Go down

Back to top

- Similar topics

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