Question

Python: Write a func that will create a list of random numbers. The function will take...

Python:

Write a func that will create a list of random numbers. The function will take in two parameters. The first parameter specifies how many values to generate and

the second parameter is the highest random # (2 is the minimum) that the func generates.

To get the random numbers, you may use this line of code:

y = random.randint (2,max), where max is the highest possible random #, INCLUSIVE.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Output:

CODE(please refere screenhot for proper indentation):

#import random

import random

#returns a list as specified in the question

def randList(n,max):

#initialize result list as empty

result=[]

#for i=0 to n-1(run loop n times)

for i in range(n):

#generate random number within the range 2,max

number=random.randint(2,max)

#append the random number to result

result.append(number)

#return result

return result

#take inputs from the user

n,max=int(input("Enter number of items: ")),int(input("Enter max: "))

#print the list returened by randList

print(randList(n,max))

Add a comment
Know the answer?
Add Answer to:
Python: Write a func that will create a list of random numbers. The function will take...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How to write python code that is a dice rolling function that generates random numbers. The...

    How to write python code that is a dice rolling function that generates random numbers. The dice rolling function takes two arguments: the first argument is the number of sides on the dice and the second argument is the number of dice. The function returns the sum of the random dice rolls. For example, if I call roll dice(6,2) it might return 7, which is the sum of randomly chosen numbers 4 and 3. It somewhere along the lines of:...

  • Python Write a function that takes in two numbers as parameters. The function will then return...

    Python Write a function that takes in two numbers as parameters. The function will then return the value of the first parameters squared by the second parameter. Print the value of the return statement. Take a screenshot of both your code and your properly executed code after you have run it. Submit the screenshots here along with your .txt file.

  • Please Use Python and provide explanations!!!! 1. Write a function called multiply_and_print that takes two numbers,...

    Please Use Python and provide explanations!!!! 1. Write a function called multiply_and_print that takes two numbers, multiplies them together, and prints out the sentence '____ times ____ is ____'. Ask the user for two numbers, and call multiply_and_print with their two numbers as arguments. 2.Write a function called roll_dice that rolls two six-sided dice and prints out the result of each die. Call it three times. (Remember, you can import the random module with the statement import random, and then...

  • l Question 2 -JS and Python a) Write JavaScript code to create a function called "sortstingsDesc"...

    l Question 2 -JS and Python a) Write JavaScript code to create a function called "sortstingsDesc" that will sort an array of string suppiied as a parameter in descending order. (4) Write Python code to create a function called "addToFront" that will accept two parameters the list of information and the value to be added and place the value to the beginning of the list. [4) b)

  • Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called...

    Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called HelperClasses and create a class inside it called Helpers Inside Helpers, create 8 static methods as follows: 1.) Max, Min, Standard_Deviation, Mean a.) Each of these should take a list as a parameter and return the calculated value 2.) Bubble a.) This should take a list as a parameter and return the sorted list 3.) Median a.) This should take a list as a...

  • Exercise 1 - Create a List to Sum Values Write a python script that sums the...

    Exercise 1 - Create a List to Sum Values Write a python script that sums the values in a list called add_list that contains the following values: (10, 2, -4, 8). Make sure you include a for loop when iterating through the list to sum the values. Take screenshots of the code and output. Exercise 2 – Create a Dictionary Write a python script that prints a dictionary where the key numbers are 1, 2, 3, 4, and 5 and...

  • PYTHON Generate a list of 50 random numbers ranging from 1 to 100 & use a...

    PYTHON Generate a list of 50 random numbers ranging from 1 to 100 & use a function that will remove duplicates from this list, compact it, and print the original and resulting lists. It MUST be well commented code with a description of the behavior.

  • Write a program that writes a series of random numbers to a file. Each random number...

    Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500 inclusive. 1.Use a file called randoms.txt as a input file and output file a. If you go to open the file and its not there then ask the user to create the file     and then quit 2. Ask the user to specify how many random numbers the file will hold. a.Make sure that the...

  • Write a Python function that will take a string and a list as its only parameters....

    Write a Python function that will take a string and a list as its only parameters. The function needs to return a new string that is the original string with all of the characters appearing in the list parameter replaced with an asterisk(*). The returned string needs to have the remaining characters appear in the same location as the characters they replaced. Hint/Reminder: Note you can make a string out of characters optimally without repeatedly using the concatenation operator.

  • Write a python program where you create a list (you an create it in code you...

    Write a python program where you create a list (you an create it in code you do not have to use input() statements) that represents the total rainfall for each of 12 months (assume that element 0 is January and element 11 is December). The program should calculate and display the: 1) total rainfall for the year; 2) the average monthly rainfall; 3) the months with the highest and lowest amounts. You need to figure out how to access each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT