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 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 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...
Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
write a function that return a list of row numbers in matrix with removing the wrong...
write a function that return a list of row numbers in matrix with removing the wrong value. Ex: remove_row( matrix, wro) if matrix = [[5,2,8],[6,7,20],[10,25,9]] wro= 20 then output will be [1,2] Do not use any built in functions.
Write a Java program to implement a Single Linked List that will take inputs from a...
Write a Java program to implement a Single Linked List that will take inputs from a user as Student Names. First, add Brian and Larry to the newly created linked list and print the output Add "Kathy" to index 1 of the linked list and print output Now add "Chris" to the start of the list and "Briana" to the end of the list using built-in Java functions. Print the output of the linked list.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT