Question

In: Computer Science

create a python function (only) that generates 10 random numbers within a specific range. Every time...

create a python function (only) that generates 10 random numbers within a specific range. Every time a number is generated, it is appended to a list (you need to initialize a list). Then the function counts how many times a number is repeated in the created list (you can choose any number to count). The function returns the list, the number you have chosen and its count.

--define the function here ---

Solutions

Expert Solution

Source code of the program is is given below.Detailed comments are included for better understanding the code.Screen shot of the code and output are also attached.If find any difficulty, feel free to ask in comment section. Please do upvote the answer.Thank you.

Source code

# importing random module to generate random numbers
import random
# function definition
def randomCount():
# creating an empty list
randomList = []
# for loop to create 10 random numbers
for i in range(0,10):
# generating random number within the range(1,20)
n = random.randint(1,20)
# appending the number into the list
randomList.append(n)
# prompt user to enter number to be counted
number=int(input("Enter the number to be counted: "))
# initialize count with 0
count=0
# iterate through the list values
for i in range(0,10):
# if the list element is the number,then increment count by 1
if randomList[i]==number:
count=count+1
# return randomList,number and count
return randomList,number,count
# main() function
def main():
# calling randomCount() function
randomNumbers,num,count=randomCount()
# printing the returned values
print("The produced random number list is : ",randomNumbers)
print("The counted number is: ",num)
print("Count is: ",count)
# calling the main() function
main()

Screen shot of the code

Screen shot of the output


Related Solutions

1. Create a program that generates n values in range [low, high]. • Create a function...
1. Create a program that generates n values in range [low, high]. • Create a function generate_vals which takes as input an array of double values and three integers representing the size of the array, low value of range, and high value of range, respectively. The function should use rand() to generate the requested number of values. • Prompt the user to enter the size of their array as shown below. It cannot exceed a maximum size of 128. If...
Create a program that generates a file of random numbers, and then prints them in neat...
Create a program that generates a file of random numbers, and then prints them in neat fashion to another file, and also saves to that file the average and standard deviation of those numbers. I) First, you would need to generate a file of random numbers that consists of N random numbers (100 < N < 1000). Each random digit should be a real number (type double) between 0 and 50. This file and its digits would now serve as...
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into...
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
Create a program RandomFile.java that generates files with random numbers/characters. You are required to write the...
Create a program RandomFile.java that generates files with random numbers/characters. You are required to write the following three methods in the class RandomFile: ​public static void randomBinaryFile(String fileName, int length) ​public static void randomNumberFile(String fileName, intlength) ​public static void randomCharFile(String fileName, int length) The parameter “fileName” specifies the file name, and “length” specifies the length of the sequence in the file. ● randomBinaryFile will generate a file containing a sequence of 0 or 1 of the specified length; ● randomNumberFile...
In Excel, the RAND function generates random numbers between 0 and 1 compute the expectation and...
In Excel, the RAND function generates random numbers between 0 and 1 compute the expectation and Standard deviation. Hints a = 0 , b = 1 P(x1<= X <= x2) = F(x2) - F(x1)
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers...
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times,...
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times, each time using a different syntax to define the list. Write a while loop that prints the numbers from 1 to 10. Convert your previous loop into a for loop. Rewrite your for loop to only have one number in the range. Write a for loop to print out each item of your list of 10 numbers, all on the same line, separated by...
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times,...
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times, each time using a different syntax to define the list. Write a while loop that prints the numbers from 1 to 10. Convert your previous loop into a for loop. Rewrite your for loop to only have one number in the range. Write a for loop to print out each item of your list of 10 numbers, all on the same line, separated by...
Using python Create a function that inputs a list of numbers and outputs the median of...
Using python Create a function that inputs a list of numbers and outputs the median of the numbers. sort them and them show the output.
- Create a list with 40 integer random numbers - With a function (def) create two...
- Create a list with 40 integer random numbers - With a function (def) create two new lists from the list created by random numbers, in which on one are the even elements and on the other the odd elements - Create two variables with the length of both new lists and print the variables All exercices must be done in Phyton
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT