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
Oduvanchick [21]
2 years ago
7

find_cow(name, cows) Given a name and a Python list of Cow objects, return the Cow object with the specified name. If no such Co

w object can be found, return None.
Computers and Technology
1 answer:
nadya68 [22]2 years ago
4 0

Using the computational knowledge in python it is possible to write a code that Given a name and a Python list of Cow objects

<h3>Writting the code in python:</h3>

<em>def load_cows(filename):</em>

<em>      cow_dict = dict()</em>

<em>    f = open(filename, 'r')</em>

<em> </em>

<em>    for line in f:</em>

<em>        line_data = line.split(',')</em>

<em>        cow_dict[line_data[0]] = int(line_data[1])</em>

<em>    return cow_dict</em>

<em>def greedy_cow_transport(cows, limit=10):</em>

<em>       trips = []</em>

<em>    cowsCopy = cows.copy()</em>

<em>    sortedCows = sorted(cowsCopy.items(), key=lambda x: x[1], reverse = True)</em>

<em>    while sum(cowsCopy.values()) > 0:</em>

<em>        ship = []</em>

<em>        total = 0</em>

<em>        for cow, value in sortedCows:</em>

<em>            if cowsCopy[cow] != 0 and value + total <= limit:</em>

<em>                ship.append(cow)</em>

<em>                total += value</em>

<em>                cowsCopy[cow] = 0</em>

<em>        trips.append(ship)</em>

<em>    return trips</em>

<em>def brute_force_cow_transport(cows,limit=10):</em>

<em>     trips = []</em>

<em>     possibilities = []</em>

<em>    for i in power_list:</em>

<em>        ship = []</em>

<em>        for j in i:</em>

<em>            ship_weights = []</em>

<em>            for k in j:</em>

<em>                ship_weights.append(cows[k])</em>

<em>                #print(ship_weights)</em>

<em>            ship.append(sum(ship_weights))</em>

<em>            #print(ship)</em>

<em>        if all(d <= limit for d in ship):</em>

<em>            possibilities.append(i)</em>

<em>      pruned_possibilities = []</em>

<em>    for k in possibilities:</em>

<em>        if k not in pruned_possibilities:</em>

<em>            pruned_possibilities.append(k)</em>

<em>    # now find the minimum list length:</em>

<em>    min_list_len = min(map(len, pruned_possibilities))</em>

<em>    for l in pruned_possibilities:</em>

<em>        if len(l) == min_list_len:</em>

<em>            return l</em>

<em>       </em>

<em>def compare_cow_transport_algorithms():</em>

<em>       greedy_start = time.time()</em>

<em>    greedy_results = greedy_cow_transport(cows, limit = 10)</em>

<em>    greedy_end = time.time()</em>

<em>    print('Greedy Algorithm time:', greedy_end -greedy_start)</em>

<em>    brute_force_start = time.time()</em>

<em>    brute_force_results = brute_force_cow_transport(cows, limit = 10)</em>

<em>    brute_force_end = time.time()</em>

<em>    print('Brute force time:', brute_force_end - brute_force_start)</em>

<em>    print('Greedy Algorithm results:', greedy_results)</em>

<em>    print('Number of trips returned by Greedy Algorithm:', len(greedy_results))</em>

<em>    print('Brute Force Algorithm results:', brute_force_results)</em>

<em>    print('Number of trips returned by Brute Force Algorithm:', len(brute_force_results))</em>

   

See more about python at brainly.com/question/13437928

#SPJ1

You might be interested in
Which two graphs best represent the motion of an object falling freely?
larisa [96]
The graph would have to be pointing completely down to be falling freely.
4 0
3 years ago
Each generation is set apart from the previous generation because of an innovation.
ehidna [41]

Answer:

Second Generation: transistors

Third Generation: integrated circuits

First Generation: vacuum tubes

Explanation:

Generations of computers are categorized based on the technologies that were used in them.

Given innovations or technologies are:

<u>transistors :</u>

Transistors were introduced in the second generation in place of vacuum tubes.

<u>integrated circuits :</u>

Integrated circuits were introduced in the third generation. An IC consists of multiple transistors.

<u>vacuum tubes:</u>

The very first generation of computers used vacuum tubes to do the calculations. the only drawback was that the tubes used to heat up very soon.

Hence,

Second Generation: transistors

Third Generation: integrated circuits

First Generation: vacuum tubes

3 0
3 years ago
Who is known as Father of Computer?
MrMuchimi
<h2>• Father=Charles Babbage</h2>

<h2>• Mother=Ada Lovelace</h2>

\\  \\  \\  \\

6 0
2 years ago
Read 2 more answers
No links, thank you
Andrei [34K]

Answer:

The most direct effect that the internet has had on retail sales is THE DEVELOPMENT OF E-COMMERCE.

E- Commerce refers to the commercial transactions that are conducted via the internet. The advance in technology has makes it possible for the retailers to advertise their products and get across to the consumers via the internet. Buying and selling on the internet is now more preferable to most people than the traditional buying and selling because of its convenience.

4 0
2 years ago
Choose the parts of the browser window.
8_murik_8 [283]

Answer:

The answer is "Title bar".

Explanation:

The title bar is located on top of the screen, its color blue, which is used in browsers. It has the function, that shows the title of the web page, that you currently viewing, and other choices were wrong, which can be described as follows:

  • Enter bar is the wrong option because it is not a part of the browser.
  • The back button is also known as a backspace key which is used to delete so thing, which is written by keyboard, that's why it is wrong.
  • The forward bar is used in pipe in a module that's why it's incorrect.

4 0
2 years ago
Other questions:
  • Use your own words to describe how IT/IS can support major functional areas in the business. Discuss at least two of these areas
    14·1 answer
  • Which routine is configured to be called by another routine?
    10·1 answer
  • Explain the concept of an engineering trade-offs and give an example
    6·2 answers
  • Difference between volatile and non volatile memory
    14·2 answers
  • A painting company has determined that for every 115 square feet or wall space, one gallon of paint and eight hours of labor wil
    11·1 answer
  • The market is in <br> until the price of goods reflects equal supply and demand.
    10·1 answer
  • Which of these statements about the truck driving occupation in the U.S. are accurate?
    12·2 answers
  • Suppose you are among those who believe that the NLRA should be transformed. What arguments support the claim that a complete ov
    6·1 answer
  • What is the positional weigh of the digit 7 in the octal number 7642 ?​
    15·1 answer
  • A. All methods in an interface must be _________________ _________________________.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!