Ask Question
14 February, 09:49

Write a function called createList that will create and fill a list of any size with random numbers in the range of 1 - 100. This function should take the size of the list as a parameter to the function. It should return the created list.

+3
Answers (1)
  1. 14 February, 10:04
    0
    The solution is written in Python code:

    import random def createList (size) : newList = [] for i in range (size) : newList. append (random. randint (1,101)) return newList

    Explanation:

    Since we need to generate random number, we import random module to our program (Line 1).

    Next we create a function createList that takes one input parameter, size (Line 2).

    In the function body, we create an empty list, newList (Line 3).

    We create a for-loop to iterate for size number of rounds and in each iteration generate a random number between 1 - 100 using the randint method from the random module and append it to the newList (Line 4-5).

    At last return the newList as function output (Line 7).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a function called createList that will create and fill a list of any size with random numbers in the range of 1 - 100. This function ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers