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
What are the differences and similarities of computer virus and biological virus. Give 4 examples
Papessa [141]

Answer:

During recent months, we’ve witnessed an unexpected and distressing pandemic of a coronavirus disease. What I find especially distressing about it is how the worldwide adversity was caused by just a tiny thing — namely, a virus called SARS-CoV-2.

However, biological viruses have always been a potent threat to humanity, as historic pandemics have proved. No wonder viruses became an ideal weapon model in a totally different world — a world of programming. The first computer viruses were created as early as in the 1970s. Starting as pranks, they evolved to become a major threat to the stability of computer networks worldwide. And the more I think of viruses, both biological and digital, the more amazed I am by their similarities.

We don’t know what kind of challenges viruses of either type will cause in the future, but understanding how they infect, the symptoms they induce, how they spread, and the damage they can cause can help us fight both.

The Common Thread

Let’s start with the basics: What does a virus look like?

computer virus of 1999

Click image for larger version

Figure 1: Pictured on the left is an electron microscope image of SARS-CoV-2 particles - the pandemic-causing coronavirus. Source: NIAID-RML. Pictured on the right is a code snippet of a Melissa, the notorious email-spreading computer virus of 1999. Source: Gizmodo.

The images in Figure 1 might look vastly different, but, essentially, they’re the same: a string of code. In the coronavirus, it’s the RNA genome in a shell; in Melissa, it’s computer code. In both cases, the code is an “instruction” for the virus to follow.

Explanation:

here is your answer hope you will enjoy

thank you

6 0
3 years ago
Briefly describe the concept of network topology change and explain how these can be dealt with using Routing Information Protoc
Natasha2012 [34]

Answer: network topology is the arrangement of nodes which includes routers and switches so that enables connection between the server and the client.

however due to times when there is huge traffic in the nodes there needs to be an optimal path for the exchange of information which is accomplished by different routing protocols.

Explanation:

Routing Information Protocol(RIP) is one such protocol which enables to route packets from the source to the destination having the least possible traffic along its path. There are two sets of routing algorithm which are

1. Static routing protocols

2. Dynamic routing protocols.

The difference between the two is that dynamic routing protocols helps to construct the routing tables dynamically as compared to static routing.

RIP is a type of dynamic routing whereby it sends the contents of its routing table the adjacent routers every 30 seconds and whenever a route is discarded from the routing table it is marked as unusable.

RIp is supported by almost all routers and also supports load balancing which is one of it advantages.

8 0
3 years ago
Default tab stops are set in Word every _______ inch. <br> A. ½<br> B. 1<br> C. ¼<br> D. ¾
Amanda [17]
In order to help the student expand his/her knowledge I will help answer the question. This in hope that the student will get a piece of knowledge that will help him/her through his/her homework or future tests.

Default tab stops are set every one half inch across a page. This is a default measure that Microsoft established. The correct answer is letter

A. 1/2

I hope it helps, Regards.     <span> </span>
4 0
3 years ago
What is similar software engineering, Hardware engineer, Network Architect, and Web developer?
Oliga [24]

I Am Pretty Sure The Answer Is - "B"

Hope This Help's

5 0
3 years ago
What controls are available on the ribbon in a contact window
sergij07 [2.7K]

Contact solution is the answer and the work is your brain
8 0
4 years ago
Other questions:
  • Which command would you use to move a file from one location to another?
    6·2 answers
  • A bug was discovered in Canvas where the website crashes if 2 or more students are writing a discussion post at the same time. I
    10·1 answer
  • A difference between crt monitors and flat-panel displays is that most flat-panel displays use digital signals to display images
    8·1 answer
  • Your mother is sure that you were driving too fast because she knows
    10·2 answers
  • "3. 4. Simple number search We will pass you 2 inputs an list of numbers a number, N, to look for Your job is to loop through th
    5·1 answer
  • Why is it unlawful for an employer to refuse to employ someone based solely on their gender without evidence that such a charact
    9·1 answer
  • Consider having three String variables a, b, and c. The statement c = a + b; also can be achieved by saying_____________.a. c =
    11·1 answer
  • The signal(s)that control the direction that data is transferred on its buslines is the _________ signal(s).
    11·1 answer
  • &gt;What is the output of the following code:
    5·1 answer
  • What is a task that is not associated with loading existing data into a new ERP system.
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!