Answered 6 days AfterMay 17, 2021

Answer To: pfa

Shashank answered on May 24 2021
130 Votes
Movie_function.py
#[movie name, gross earning, year, rating out of 10, number of ratings]. input format
def get_name(movie_name): # Get the movie name from the given List function
name=movie_name[0]
return name # return
ing movie name
def get_gross(movie): # Get the gross from the given List function
gross=movie[1]
return gross # returning gross earning
def get_rating(movie): # Get rating from the given List function
rating = movie[3]
return rating # returning rating out of 10
def get_num_ratings(movie): # Get number of ratings from the given List function
num_rating = movie[4]
return num_rating # returning number of ratings
## Better movie function ##
def better_movies(movie_name, lst):
better_movie = [movie for movie in lst if movie_name in movie] #initial we are fetching complete information about input movie
better_movie_list = [movie for movie in lst if get_rating(better_movie[0]) < get_rating(movie)] #by using get_rating function we are checking ratings
# which having more rating than inputted movie
return better_movie_list # Returning movies which having more ratings and related information

def average(category, lst):
if category == 'rating': #checking category is rating or not
index = get_rating #Returning getrating function to get rating of the movie
elif category == 'gross': #checking category is gross or not
index = get_gross #Returning get_gross function to get gross earning of the movie
elif category == 'number of ratings' or category == 'number of ratings'.replace(' ',''):#checking category is Number of rating
index = get_num_ratings #Returning get_num_ratings function to Number of rating of the movie
else:
index =-1 #its not rating,gross,number of rating then this part will be take as invalid
avg=0 #initializing variable
if index != -1: #checking category is valid or not
for i in lst: # To get result we are looping data
avg+=index(i) #here storing data in avg variable
Result = avg/len(lst) #calculating avrage by avg...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here