Help with passing the arguments.
This program is supposed to ask for how many numbers do you want. I would stick with ten. Then how many numbers in a randrange (upper limit) Please choose 100
After a list is generated it is supposed to sort the numbers and look for a certain number. The print statement is not necessary I was just doing that for testing. It keeps crashing on the OSS function. So basically I am having trouble with passing arguments.
Any suggestions.

from random import randrange
import time
def main():
    print "Choose how many numbers you want"
    print "Numbers must be less than upper limit"
    h_nums = input("How many numbers do you want: ")
    r_nums = input("Please input upper range limit: ")
    f_num = input("What number are you looking for.  Stay within range: ")
    start = time.clock()
    oss(h_nums, f_num)
    elapsed = (time.clock() - start)
    print elapsed

def createRandnums(num1,num2):
    alist = []
    for i in range(num1):
        total = randrange(1,num2,1)
    print alist
    return alist

def oss(alist, item):
    pos = 0
    found = False
    stop = False
    while pos < len(alist) and not found and not stop:
        if alist[pos] == item:
            found = True
            if alist[pos] > item:
                stop = True
                pos = pos+1

    return found
6 Years
Discussion Span
Last Post by Gribouillis

At line 8, you are not using the list returned by createRandnums(), and you are passsing h_nums to oss() at line 11 instead of the list. Also I can't see where the list is sorted.

If the list is sorted, you should have a look in the bisect module to implement oss().

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.