In: Computer Science
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
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
===========================================================