Copy the following Python fuction discussed in class into your file:
from random import *
def makeRandomList(size, bound):
a = []
for i in range(size):
a.append(randint(0, bound))
return a
a. Rename the function sumList as meanList and modify it so that it finds the average of the list. The average is the sum divided by the size (len) of the list. Make sure that the function doesn't give you an error when it is called on an empty list.
The function should also return the result and not print it. If the list is empty, the function should return 0.
Test the function in the console to see if it works.
b. Rename the function searchList as countVal and modify it so that it returns the number of times the value can be found in the list. If the list is empty or does not contain the value, it should return 0.
Test this second function a few times the same way as the first one.
c. Modify the testing part, including the printed messages, to reflect the new functions.
Test the program to make sure that it works fine.
import random
def makeRandomList(size, bound):
a = []
for i in range(size):
a.append(random.randint(0, bound))
return a
def meanList(data):
if(len(data)==0):
return 0
total=0
for x in data:
total=total+x
return (total/len(data))
def countVal(data,n):
if(len(data)==0):
return 0
count=0
for x in data:
if n==x:
count=count+1
return count
data=makeRandomList(10,100)
print(data)
print("Average : ",meanList(data))
print("10 occurs in the list : ",countVal(data,11))
data=makeRandomList(10,100)
print(data)
print("Average : ",meanList(data))
print("5 occurs in the list : ",countVal(data,5))

Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Copy the following Python fuction discussed in class into your file: from random import * def...
import random
def doTest(operation):
## complete your work here ##
# return True for now
return True
responsesCorrect = 0
print("The software will process a test with 10 questions ……
")
for compteur in range (10):
operation = random.randint(0,1)
if doTest(operation) == True:
responsesCorrect += 1
print(responsesCorrect, "Correct responses")
if responsesCorrect <= 6 :
print("Ask some help from your instructor.")
else:
print("Congratulations!")
Requirement: You must use the format provided below and
then complete the fill! Python! Thanks!...
import random import turtle def isInScreen(win,turt): leftBound = -win.window_width() / 2 rightBound = win.window_width() / 2 topBound = win.window_height() / 2 bottomBound = -win.window_height() / 2 turtleX = turt.xcor() turtleY = turt.ycor() stillIn = True if turtleX > rightBound or turtleX < leftBound: stillIn = False if turtleY > topBound or turtleY < bottomBound: stillIn = False return stillIn def main(): wn = turtle.Screen() # Define your turtles here june = turtle.Turtle() june.shape('turtle') while isInScreen(wn,june): coin = random.randrange(0, 2) if...
Using Python.
You will create two classes and then use the provided test program to make sure your program works This means that your class and methods must match the names used in the test program You should break your class implementation into multiple files. You should have a car.py that defines the car class and a list.py that defines a link class and the linked list class. When all is working, you should zip up your complete project and...
//Your programs should not crash under any circumstances. import java.util.Scanner; public class LetterCount { public static int countBs(String word) { for (int i = 0; i < word.length(); i++) { int counter = 0; if ((word.charAt(i) == 'b') || (word.charAt(i) == 'B')) { counter++; } } return counter; } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.printf("Please enter a word: "); String str = in.next(); int result = countBs(str); System.out.printf("%s contains letter B %d times.\n", str,...
FUNCTIONS In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, a return will not be allowed! Write and test a function sum_list(nums) Where nums is a...
CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class. A queue class is a First-In-First-Out data structure. To understand a queue, think of a checkout line at a grocery store: the person at the front is served first (removed), and people are added to the line from the back end. class queue : private unorderedArrayListType { public: bool isEmpty() const; // test whether queue is empty // Post: returns true if queue is...
Next, create a simple benchmark experiment using the timeit module as we did in class. • Run each of your functions 1 time (e.g. quad_timest timeit(number 1)) for list sizes ranging from 1,000 to 20,000 in increments of 1,000. You will notice that the quadratic time function really starts to slow down as the size of the list Increases Display a table the run times (should look something like this: ratio 906 Size Tinear 3000, 0.00000 15000 3000, 0.0001202000. 5000,...
The file Sorting.java contains the Sorting class from Listing 9.9 in the text. This class implements both the selection sort and the insertion sort algorithms for sorting any array of Comparable objects in ascending order. In this exercise, you will use the Sorting class to sort several different types of objects. 1. The file Numbers.java reads in an array of integers, invokes the selection sort algorithm to sort them, and then prints the sorted array. Save Sorting.java and Numbers.java to...
python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key. 2.Convert Newton’s method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of...
1. Your project will include the following three files: A header file: dynamicArray.h that includes a list of function prototypes as enumerated in the next section. An implementation file: dynamicArray.cpp that implements the functions declared in the header file. A test driver file: dynamicArray-main.cpp that includes the main() function so that you can test all the functions you've implemented above. 2. The header file dynamicArray.h will include the following list of functions: constructing a dynamic array of the specified size...