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.

  • Using Python, write an application that tests an elementary school student on their basic math skill....

    Using Python, write an application that tests an elementary school student on their basic math skill. The program should generate random equations to be solved with numbers between 0 and 12. The student should be told if they are correct or incorrect. If the user enters the word DONE, the program should end by telling the student their average (i.e. if they correctly answer 4 out of 8 problems, their average would be 50%). To help modularize you code, create...

  • 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.

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