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
From MCYT who was the the one who said "SUCK IT GREEN BOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOY"
Papessa [141]

Answer:

Tommyinnit

Explanation:

8 1
3 years ago
Read 3 more answers
Which tools can Object Drawing Mode be applied to?
Deffense [45]

Answer:

• Line Tool

• Rectangle Tool

• Oval Tool

• Pencil Tool

• Brush Tool.

Explanation:

When people want to animate when using the Adobe Animate CC, it is vital for them to know how to draw shapes like squares, lines, ovals, rectangles, and circles. This is to enable such individuals understand how to draw objects as it can be difficult if they do not know how to draw these shapes.

The tools that Object Drawing Mode be applied to include:

• Line Tool

• Rectangle Tool

• Oval Tool

• Pencil Tool

• Brush Tool.

When the tool is being selected, it should be noted that the option for the drawing mode will be shown in the Property Inspector panel or it can also be seen in the tools panel.

5 0
3 years ago
Write a function named ​isDivisible​ that takes two parameters
nirvana33 [79]

Answer:

def isdivisible():

   maxint=input("Enter the Max Int")

   int1=0

   int2=0

   int1=input("Enter the first Integer")

   int2=input("Enter the second Integer")

   tup1=(int1, int2)

   print(tup1)

   i = 1

   for i in range(1, int(maxint)-1):

       if int(tup1[0])%i==0 & int(tup1[1])%i==0:

           print(i)

       else:

           continue

       

   

isdivisible()    

1.2 Outputs

First test case:

Enter the Max Int6                                                                                                            

Enter the first Integer2                                                                                                      

Enter the second Integer8                                                                                                      

('2', '8')                                                                                                                    

1                                                                                                                              

2      

Second test case: returning empty list

Enter the Max Int2                                                                                                            

Enter the first Integer13                                                                                                      

Enter the second Integer27                                                                                                    

('13', '27')

Test case 3:

Enter the Max Int4                                                                                                            

Enter the first Integer8                                                                                                      

Enter the second Integer10                                                                                                    

('8', '10')                                                                                                                    

1                                                                                                                              

2        

Explanation:

The program is as above, and the three test cases are also mentioned. We have created a tuple out of two input integer, and performed the output as required.

3 0
3 years ago
bing bong bing bong bing bong bing bong bing bong bing bong bing bong bing bong bing bong bing bong bing bong bing bong bing bon
Artist 52 [7]

Answer:

Is this free points? bingbongbingbongbingbongbingbongbingbongbingbong hehe have a nice day :)

Explanation:

3 0
3 years ago
Read 2 more answers
Write a program that will read in aweight in kilograms and grams and will output the equivalent weightin pounds and ounces. Use
ozzi

<u>C++ program for converting kilograms and grams to pounds and ounces</u>

#include <iostream>

using namespace std;

void computation(double kilog, double gram, double& pon, double& oun) /*defining function for computing*/

{

pon = kilog*2.2046;/*Formula for converting*/

oun= gram*0.03527;

}

void output(double pon,double oun)/*For printing output*/

{

   cout << "Pounds are: " << pon << endl;

   cout << "Ounce are: " << oun << endl;

}

void input(double &kilog,double&gram)/*for taking output*/

{

   cout << "Enter kilograms to convert: ";

   cin >> kilog;

  cout << "Enter grams to convert: ";

   cin >> gram;

}

int main() //driver function

{

double kilog = 0.0,gram = 0.0,oun=0.0,pon=0.0;//Initializing

int choice = 0;

while (1) {  

cout << "Enter- 1 for converting kilogram and grams to pounds and ounces" << endl;

cout << "Enter-2 for exiting" << endl;

cout << "Please Enter choice: ";/*Asking choice from user*/

cin >> choice;

if (choice == 1) {

input(kilog,gram);/*Calling function for taking input*/

computation(kilog, gram, pon, oun); /*calling function for computing*/

output(pon,oun);/*calling function for output*/

}

else {

return 0;

}

}

}

<u>Output</u>

Enter- 1 for converting kilogram and grams to pounds and ounces

Enter-2 for exiting

Please Enter choice:1

Enter kilograms to convert:20

Enter grams to convert:10

Pounds are: 44.092

Ounce are: 0.3527

Enter- 1 for converting kilogram and grams to pounds and ounces

Enter-2 for exiting

Please Enter choice: 2

6 0
4 years ago
Other questions:
  • Which mode can students use to ensure that their information is not saved in their Chrome browser
    15·1 answer
  • Explain what might happen if two stations are accidentally assigned the same hardware address?
    15·1 answer
  • Suppose as a computer programmer, you have been assigned a task to develop a program to store the sorted data in ascending order
    9·1 answer
  • What feature is available to add a suggestion in the margin of someone else's document?
    7·1 answer
  • What would happen if computers only had input peripherals and a CPU
    11·2 answers
  • This week you will learn about basic code structure. The term structure, as it relates to programming, refers to the decisions y
    14·1 answer
  • Information is data converted into useful, meaningful context. What are data characteristics that change or vary over time?
    8·1 answer
  • In computer science how can you define "copyright, designs and patents act 1988"?​
    8·1 answer
  • Whose guidelines should you follow for the destruction of storage media such as thumb drives, Zip drives, and computers?
    6·1 answer
  • Jacob has a text file open, and he is typing on the keyboard. What is the best description of how the
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!