Ask Question
29 July, 23:10

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. 30 July, 01:35
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers