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.
- In main, generate a random
integer
that is greater than 5 and less than 13. - Print this number on its own line.
- Call the makelist function with the random integer as sole argument.
-
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.
-
Back in main, catch the returned list and sort it.
- Finally, use a for loop to display the sorted list elements, all on one line,
- 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