Ask Question
17 June, 07:58

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.

+5
Answers (1)
  1. 17 June, 08: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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers