Skip to content
Advertisement

How do I find the highest float from a list?

I have made a program that gets a movie you pick from a list and tells you its directors and rating it also tells you if a movie is the highest-rated. I want the program to do the same thing it is doing but instead of just checking if the title is 5 stars, it checks if the rating is higher than all the other floats.

JavaScript

Advertisement

Answer

In Python you can get the highest value in a list (or in an iterable in general) with the built-in function max:

JavaScript

In your case you just have to put the ratings into a list:

JavaScript

and then find the highest value:

JavaScript

An even better solution would be this one suggested by @Matthias:

JavaScript

This is the same thing, but it allows you to avoid initializing a useless list.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement