Question

In: Computer Science

Write a function that inputs a list of numbers and a percentile value from 0 to...

  1. Write a function that inputs a list of numbers and a percentile value from 0 to 1 and have the function return the element that is at that percentile (or greater than). You can use this website for the steps https://www.indeed.com/career-advice/career-development/how-to-calculate-percentile check out the step for “Follow these steps to calculate the kth percentile”

def percentileReturn(list1,percentile):#function which returns the list of elements which are greater than or equal to the percentile
list2=[i for i in list1 if i>=percentile] #creating list2 which have elements from list1 which are greater than or equal to percentile
return list2 #returning list2
values=list(map(float,input("Enter numbers: ").split())) #values
percentile=float(input("Enter percentile: ")) #percentile
print(percentileReturn(values,percentile)) #calling percentileReturn function and testing for a sample value

This is what I put and my prof said: I get an error.     values=list(map(float,input("Enter numbers: ").split())) #values

ValueError: could not convert string to float: '1,2,3,4'

this is for python

Solutions

Expert Solution

Thanks for the question, Since your professor is giving input the grades separated by comma and not space, you need to split() it by comma.

Here is the updated code and output screenshot. Please check with your professor and let me know for any changes.

==========================================================================

import math

# function which returns the list of elements which are greater than or equal to the percentile
def percentileReturn(list1,  percentile):
    size = len(list1)
    return sorted(list1)[int(math.ceil((size * percentile))) - 1]


values = list(map(float, input("Enter numbers: ").split(',')))  # values
percentile = float(input("Enter percentile: "))  # percentile
print(percentileReturn(values, percentile))  # calling percentileReturn function and testing for a sample value

===========================================================


Related Solutions

Write a function add(vals1, vals2) that takes as inputs two lists of 0 or more numbers,...
Write a function add(vals1, vals2) that takes as inputs two lists of 0 or more numbers, vals1 and vals2, and that uses recursion to construct and return a new list in which each element is the sum of the corresponding elements of vals1 and vals2. You may assume that the two lists have the same length. For example: >>> add([1, 2, 3], [3, 5, 8]) result: [4, 7, 11] Note that: The first element of the result is the sum...
Write a function printTwoLargest() that inputs an arbitrary number of positive numbers from the user. The...
Write a function printTwoLargest() that inputs an arbitrary number of positive numbers from the user. The input of numbers stops when the first negative or zero value is entered by the user. The function then prints the two largest values entered by the user. If no positive numbers are entered a message to that effect is printed instead of printing any numbers. If only one number is inputted, only the largest is printed out (see 2nd example below). Sample output:...
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.
Write a function that will accept a list of numbers and an integer (n). The function...
Write a function that will accept a list of numbers and an integer (n). The function should return a list containing every nth item from the input list, always starting with the first item in the list. The original list should not be modified. For example, if the function is passed the list [8, 3, 19, 26, 32, 12, 3, 7, 21, 16] and the integer 3, it will return the list [8, 26, 3, 16] If the function is...
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them
Write a function which receives a list and returns a number. In the list, all numbers...
Write a function which receives a list and returns a number. In the list, all numbers have been repeated twice except one number that is repeated once. The function should return the number that is repeated once and return it.write a python program for this question. use main function.
Write a Racket function that will take a list of numbers as a parameter and return...
Write a Racket function that will take a list of numbers as a parameter and return true if they all are positive, and false otherwise. You are NOT required to check the type of elements in the list. (please do on racket language)
Write a Racket function that will take a list of numbers as a parameter and return...
Write a Racket function that will take a list of numbers as a parameter and return true if they all are positive, and false otherwise. You are NOT required to check the type of elements in the list.
Write a function in Python to compute the sample mean of a list of numbers. The...
Write a function in Python to compute the sample mean of a list of numbers. The return value should be the sample mean and the input value should be the list of numbers. Do not use a built-in function for the mean. Show an example of your function in use.    Thank You
Write a function myfn6 which takes as inputs vector u and value a, and output as...
Write a function myfn6 which takes as inputs vector u and value a, and output as vector w with its elements being “True, ” or “False, ”(w = [True, False, False, …, True]). Such that “True, ” means a is in u and “False, ” means a is not in u. Test your code for u = [0, -3, 1, 1, 2, 2, 6, 2] and a = 9, a = 1 and a = 2. Copy your code together...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT