Question

In: Computer Science

#Write a function called find_max_sales. find_max_sales will #have one parameter: a list of tuples. Each tuple...

#Write a function called find_max_sales. find_max_sales will
#have one parameter: a list of tuples. Each tuple in the
#list will have two items: a string and an integer. The
#string will represent the name of a movie, and the integer
#will represent that movie's total ticket sales (in millions
#of dollars).
#
#The function should return the movie from the list that
#had the most sales. Return only the movie name, not the
#full tuple.


#Below are some lines of code that will test your function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print: Rogue One
movie_list = [("Finding Dory", 486), ("Captain America: Civil War", 408), ("Deadpool", 363), ("Zootopia", 341), ("Rogue One", 529), ("The Secret Life of Pets", 368), ("Batman v Superman", 330), ("Sing", 268), ("Suicide Squad", 325), ("The Jungle Book", 364)]
print(find_max_sales(movie_list))

Solutions

Expert Solution

Explanation:

Here is the method which takes the movie_list, traverses each tuple using a for loop and then, assigns the maximum value tuple name to max_name variable.

Code:

def find_max_sales(movie_list):
  
maximum = 0
max_name = ''
for each_t in movie_list:
if each_t[1]> maximum:
maximum = each_t[1]
max_name = each_t[0]
  
return max_name


movie_list = [("Finding Dory", 486), ("Captain America: Civil War", 408), ("Deadpool", 363), ("Zootopia", 341), ("Rogue One", 529), ("The Secret Life of Pets", 368), ("Batman v Superman", 330), ("Sing", 268), ("Suicide Squad", 325), ("The Jungle Book", 364)]
print(find_max_sales(movie_list))

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!


Related Solutions

using python 1. #Write a function called multiply_by_index. multiply_by_index #should have one parameter, a list; you...
using python 1. #Write a function called multiply_by_index. multiply_by_index #should have one parameter, a list; you may assume every item #in the list will be an integer. multiply_by_index should #return a list where each number in the original list is #multipled by the index at which it appeared. # #For example: # #multiply_by_index([1, 2, 3, 4, 5]) -> [0, 2, 6, 12, 20] # #In the example above, the numbers 1, 2, 3, 4, and 5 appear #at indices 0,...
Task 4:         Tuples Explain what is the difference between list, string and tuple? Create a list...
Task 4:         Tuples Explain what is the difference between list, string and tuple? Create a list example and check whether you could change the item within the list. Create a string example and check whether you could change the item within the string. Create a tuple example and check whether you could change the item within the tuple.
#Write a function called "load_file" that accepts one #parameter: a filename. The function should open the...
#Write a function called "load_file" that accepts one #parameter: a filename. The function should open the #file and return the contents.# # # - If the contents of the file can be interpreted as # an integer, return the contents as an integer. # - Otherwise, if the contents of the file can be # interpreted as a float, return the contents as a # float. # - Otherwise, return the contents of the file as a # string. #...
Write a function that accepts a dictionary and produces a sorted list of tuples The dictionary...
Write a function that accepts a dictionary and produces a sorted list of tuples The dictionary looks like this: {‘US’: [{'Chicago, IL': ('2/1/2020 19:43', 2, 0, 0)}, {'San Benito, CA': ('2/3/2020 3:53', 2, 0, 0)}, {'Santa Clara, CA': ('2/3/2020 0:43', 2, 0, 0)}, {'Boston, MA': ('2/1/2020 19:43', 1, 0, 0)}, {'Los Angeles, CA': ('2/1/2020 19:53', 1, 0, 0)}, {'Orange, CA': ('2/1/2020 19:53', 1, 0, 0)}, {'Seattle, WA': ('2/1/2020 19:43', 1, 0, 0)}, {'Tempe, AZ': ('2/1/2020 19:43', 1, 0, 0)}], 'Australia'...
In python this structure can be represented by a set of tuples, where each tuple has...
In python this structure can be represented by a set of tuples, where each tuple has two elements. The following two lines would build the set given above and the print it. >>> L = [(’dog’,’white’), (’cat’,’black’),(’mouse’,’black’)] >>> f = set(L) >>> print(f) {(’cat’, ’black’), (’dog’, ’white’), (’mouse’, ’black’)} In the example, first we store the tuples into a list, and then we create a set with those tuples. There are obviously countless other ways to initialize f and get...
In C: Write a function definition called PhoneType that takes one character argument/parameter called phone and...
In C: Write a function definition called PhoneType that takes one character argument/parameter called phone and returns a double. When the variable argument phone contains the character a or A print the word Apple and return 1099.99 When phone contains anything else return a 0.0
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g....
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g. (“John”, “Doe”) that represents a class. Ask the user for a students first and last name and check if that student is a member of the class.
Write a function for checking the speed of drivers. This function should have one parameter: speed....
Write a function for checking the speed of drivers. This function should have one parameter: speed. 1. If speed is less than 70, it should print “Ok”. 2. Otherwise, for every 5km above the speed limit (70), it should give the driver one demerit point and print the total number of demerit points. For example, if the speed is 80, it should print: "Points: 2". 3. If the driver gets more than 12 points, the function should print: “License suspended”...
Write a function average_steps(step_records) that takes a list of records, ie, tuples in the form (date_str,...
Write a function average_steps(step_records) that takes a list of records, ie, tuples in the form (date_str, step_count), and returns the average number of steps made across all the records as an unrounded floating point number. If step_records is an empty list then None should be returned. Note: You should include and use your total_steps function. Test Result step_records = [('2010-01-01',1), ('2010-01-02',2), ('2010-01-03',3)] avg = average_steps(step_records) print(avg) 2.0 step_records = [] avg = average_steps(step_records) print(avg) None step_records = [('2010-01-01',3), ('2010-01-02',3), ('2010-01-03',3),...
solve with python 3.8 please 1,Write a function called make_squares_coordinate_pair that has one parameter - an...
solve with python 3.8 please 1,Write a function called make_squares_coordinate_pair that has one parameter - an int. The function should return a tuple containing that int and its square. Suppose you were to call your function like this: print(make_squares_coordinate_pair(5)) This should output: (5, 25) Your function MUST be called make_squares_coordinate_pair. You can write code in the main part of your program to test your function, but when you submit, your code must ONLY have the function definition! 2, Write a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT