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
How many 2/8 pound patties can she make from 7/8 of a pound of hamburger
Juli2301 [7.4K]

Answer:

3/8

Explanation:

Because 2 can't go into 7, the next best thing is 6, so 2x3 is 6 with 1/8 left over~~~~~hope this helps :) pls brainlist

7 0
3 years ago
Is a component that provides a button control in a gui application or applet?
harina [27]
<span>GUI is a graphical user interface. It is a graphical window that provides interaction with the user. 
</span>The button is a pushbutton, which can be pressed to trigger an action.<span>
A graphic control component or a control element is a component that provides a button control in a GUI application. It is also called a control element because it </span><span>is an element of interaction between the user controlling the application.</span>
7 0
4 years ago
Assume the availability of class named Date Manager that provides a static method, print Todays Date, that accepts no arguments
anygoal [31]

Answer:

DateManager.printTodaysDate();

Explanation:

As class named "DateManager" which will call the "printTodaysDate()"  static function.Static method are those who are accessed by the classname not by the object .

  • As printTodaysDate(); is a static method it means it cannot hold non static data.It hold only the static data,We cannot used super keyword in the  printTodaysDate(); function.
  • So the statement DateManager.printTodaysDate(); calls print Todays Date.
3 0
3 years ago
List at least four items that security policy should include
forsale [732]

Answer:

Purpose.

Audience.

Information security objectives.

Authority and access control policy.

Data classification.

Data support and operations.

Security awareness and behavior.

Encryption policy.

4 0
2 years ago
Which statement below is incorrect when discussing communication in the online community?
Marysya12 [62]
It's everyone's responsibility to report cyberbullying.

The tone is important whenever you are talking to someone else.

You can literally say anything in virtual world, but you should behave yourself

If everybody knows the common text phrases, then it's fine, but it will be better to talk formally.
8 0
3 years ago
Other questions:
  • What does the Autosum feature on excel do?
    15·1 answer
  • What should Timothy consider to make a successful formal presentation?
    11·2 answers
  • All waves consist of a continuous series of _____.
    11·2 answers
  • What should you keep in mind when typing a message on the Internet?use as many A.acronyms as it saves space
    7·1 answer
  • I swear I’m hopeless....
    8·1 answer
  • Write the definition of a function printLarger, which has two int parameters and returns nothing. The function prints the larger
    7·1 answer
  • The (X , y) coordinates of a certain object as a function of time' are given by Write a program to determine the time at which t
    6·1 answer
  • In python
    9·1 answer
  • Tạo thủ tục có tên _Pro04 để trả về số lượng tổng thời gian tham gia dự án Y của nhân viên có mã số X, với X là tham số đầu vào,
    5·1 answer
  • In Python, programmers use square brackets and an index range to slice multiple characters from a string.
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!