Problem Statement
The company ABC has online ice-cream store. The company wants to know the most rated ice-cream from them, based on the rating given by the customers in the online store.
The most rated ice-cream is defined as the ice-cream that has the largest rating.
Input
The first line of input is icecream_names
, space separated values, where each value represents the name of an ice-cream.
The second line of input is ratings
, space separated values, where each value is a float number representing the rating of the respective ice-cream from the first input. A rating is in the range [1, 5] in steps of one.
The above two inputs are converted to lists. And these lists are of same length.
Output
Print the name of the most rated ice-cream.
As is
The boilerplate code is already there to read the inputs from user, in the main()
function, and to print the value returned by the get_most_rated_icecream()
function. Do not edit this code.
To do ✍
get_most_rated_icecream()
has two parameters: icecream_names
and ratings
that are lists. Write code inside the function body to find the most rated ice-cream from the ratings list, and return the corresponding ice-cream name.
Example 1
Test input
choco butter vanilla cone pista
4.1 3.8 4.0 4.3 3.6
Test output
cone
Explanation
Among the ratings, 4.3
is the largest rating. And the ice-cream corresponding to this rating is the cone
.
Example 2
Test input
choco butter vanilla cone pista
4.1 4.5 3.9 4.2 4.4
Test output
butter
Explanation
Among the ratings, 4.5
is the largest rating. And the ice-cream corresponding to this rating is the butter
.
Useful References
Python Program
# Complete the following function
# Return the most rated icecream name
def get_most_rated_icecream(icecream_names, ratings):
# Boilerplate code - Do not edit the following
def main():
icecream_names = [x for x in input().split()]
ratings = [float(x) for x in input().split()]
print(get_most_rated_icecream(icecream_names, ratings))
if __name__ == "__main__":
main()
Testcase 1
choco butter vanilla cone pista
4.1 4.5 3.9 4.2 4.4
butter
Testcase 2
choco butter cone pista
4.1 4 3.9 4.2
pista
Testcase 3
choco
4.1
choco
Testcase 4
choco apple
4.1 5.0
apple
# Complete the following function
# Return the most rated icecream name
def get_most_rated_icecream(icecream_names, ratings):
max_rating = max(ratings)
index_of_max_rating = ratings.index(max_rating)
most_rated_icecream = icecream_names[index_of_max_rating]
return most_rated_icecream
# Boilerplate code - Do not edit the following
def main():
icecream_names = [x for x in input().split()]
ratings = [float(x) for x in input().split()]
print(get_most_rated_icecream(icecream_names, ratings))
if __name__ == "__main__":
main()