1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
klemol [59]
3 years ago
8

Premise: Tracy has a file that contains a list of actors and the movies in which they acted. She wants to know the top 3 ranked

actors from her list whom have acted/appeared in the most movies. ACTOR_NAME MOVIE_NAME Leonardo DiCaprio The Revenant Christian Bale Vice Morgan Freeman Shawshank Redemption Leonardo DiCaprio The Great Gatsby Christian Bale American Psycho Morgan Freeman The Dark Knight Christian Bale The Dark Knight Samuel L. Jackson Pulp Fiction Question: Write code in Java/Scala/Python to display the top 3 ranked actors appearing in the most movies based on the count of movies in which they have acted. If there are less than 3 actors in her list, display all of them. Consider all scenarios - such as, if two actors have acted in the same number of movies, they will have the same rank.

Computers and Technology
1 answer:
anzhelika [568]3 years ago
5 0

Answer:

see explaination

Explanation:

Python version : 2.7

Python program to read an input file with specified number of records to read

and output the top 3 ranked actors

The format of input file:

<number of records to read>

<actor_name>,<movie_name>

<actor_name>,<movie_name>

....

'''

#define the file name

filename = 'actors_movies.txt'

# create an empty dictionary to contain the actor name as key and number of movies they have acted as value

actors_movie_count = {}

# open the flie

fp = open(filename)

line = fp.readline() # read the first line

count = int(line)

i = 0

# loop to read count number of lines from file

while i < count:

line = fp.readline() # read a line

data = line.split(",") # split the input data into list of strings using comma as the delimiter

# check if actor name is present in the dictionary, then add 1 to its value

# strip is used to remove any leading or trailing space

if data[0].strip() in actors_movie_count:

actors_movie_count[data[0].strip()] += 1

else: # else insert a new record with actor name as its key and 1 as value

actors_movie_count[data[0].strip()] = 1

i += 1

# close the file

fp.close()

# get the list of names of actors and list of number of movies they have acted

actors = actors_movie_count.keys()

num_movies = actors_movie_count.values()

# loop to sort the actors list and num_movies list in descending order of count of movies

for i in range(len(num_movies)-1):

max = i

for j in range(i+1,len(num_movies)):

if num_movies[j] > num_movies[max]:

max = j

if max != i:

actors[max], actors[i] = actors[i], actors[max]

num_movies[max], num_movies[i] = num_movies[i], num_movies[max]

# rank the actors to add top 3 ranked actors to rank_actors list

rank = 1

rank_actors = []

# add the first actor to list

rank_actors.append(actors[0])

# loop from second to end of actors list

for i in range(1,len(actors)):

# if this actor has same number of movies as the actor before him, then assign same rank

if num_movies[i] == num_movies[i-1]:

# if rank <= 3, add the actor in rank_actors list

if rank <= 3:

rank_actors.append(actors[i])

else: # rank > 3, exit the loop

break

else: # assign 1 more rank that the previous

rank += 1

# if rank <= 3, add the actor in rank_actors list

if rank <= 3:

rank_actors.append(actors[i])

else: # rank > 3, exit the loop

break

# loop to display the top 3 ranked actors

for actor in rank_actors:

print(actor)

#end of program

see attachment for the program screenshot and output

You might be interested in
A computer _________________ is a text file that a computer can understand
Gekata [30.6K]

Answer:

A computer ___Task__ is a text file that a computer can understand

6 0
2 years ago
Case Project 9-4: Troubleshoot an IP configurationYou work at a help desk and have just received a call from an employee who say
Svetllana [295]

Answer:

To get the IP address and other information on the workstation, type 'ipconfig' for windows or 'ifconfig' or Linux and press the return key.

The subnet mask is a class B type and 169.254.14.11 IP address shows that the workstation cannot access the DHCP server, so the IP address is not properly configured for network connection.

Explanation:

A computer network is an interconnection and intercommunication of two or more computer devices. All devices in a network must have an IP address, which can be static or dynamic from a DHCP server.

When a computer is configured to receive IP address from a DHCP server, but cannot reach the server, the IP address from the range of 169 is automatically assigned to it but still would not be able to communicate with other devices in the network.

4 0
2 years ago
The collection of all component frequencies iscalled _____________
yKpoI14uk [10]

Answer:

The answer is Frequency Spectrum.

Explanation:

The frequency spectrum is range of all component frequencies.It contains all the waves which are as following:-

Gamma Rays

X-Rays

Ultraviolet

Visible light.

Infrared

Micro wave

Radio wave

These all waves have their range of frequencies.The waves that are visible to us is only the visible light.

4 0
3 years ago
Hey how was your day 50 points
lakkis [162]

Answer:

bad

Explanation:

3 0
2 years ago
Read 2 more answers
(iii) If 1 GB = 2x<br>then what is the<br>value of x?​
frez [133]
Since a Gigabyte is made of Megabytes, 500 Megabytes times 2, 2(500MB), is equal to one Gigabyte. (1000MB)
UNLESS, it wants the Windows way of storage, because one Gigabyte in Windows terms is actually 1024 megabytes... then it’d be 2(512MB) because 512MB and 512MB equals one windows storage gigabyte.
4 0
2 years ago
Other questions:
  • Which is a feature of a strong thesis statement? A) It presents only the facts. B) It is open-ended. C) It answers the central q
    15·1 answer
  • Which of the following statements is true of intrapreneurs
    15·1 answer
  • How do you add a PDF assignment to google docs and be able to edit it?
    13·1 answer
  • Answer the following questions:
    7·1 answer
  • What are the text or graphics that are lighter than the main text located in a document's background called?
    10·1 answer
  • 19. The power supply in your server has just been replaced because of power problems. Your server boots, but now there is a mess
    13·1 answer
  • How many people on here are doing edmentum online
    11·1 answer
  • The first page of a website is what?​
    5·2 answers
  • How do you customize calendar view​
    9·2 answers
  • Is Naab a system of an accounting system? A factory operations system? or both? explain your answer
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!