jeudi 21 mai 2015

program to generate a random length list of random numbers in Python

I am very new to programming and to a board like this and am in fact just starting class. I understand the basics of Python and have been banging my head against the wall with this for 2 days now. Below are the requirements for the program followed by my embarrassing attempt at the code immediately after. I'm not looking for it to be given to me but I just can't figure out how to move forward.

  1. In main, generate a random integer that is greater than 5 and less than 13.
  2. Print this number on its own line.
  3. Call the makelist function with the random integer as sole argument.
  4. Inside the makelist function:

    *make an empty list.

    *use a loop to append to the list a number of elements equal to the random integer argument. All new list elements must be random integers ranging
    from 1 to 100, inclusive. Duplicates are okay.

    *return the list to main.

  5. Back in main, catch the returned list and sort it.

  6. Finally, use a for loop to display the sorted list elements, all on one line,
  7. Separated by single spaces.

Code so far:

import random
def main():
    random_int = random.randint(6, 12)
    print (random_int)
    makelist()
def makelist():
    num_list = []
    for count in range(1, 101)
        num_list.append(random_int)

main()




Aucun commentaire:

Enregistrer un commentaire