Apr-08-2019, 10:13 PM
A colony of Aucks (super-intelligent alien bioengineers) has landed on Earth and has created new species of farm animals! The Aucks are performing their experiments on Earth, and plan on transporting the mutant animals back to their home planet of Aurock. In this problem set, you will implement algorithms to figure out how the aliens should shuttle their experimental animals back across space.
The aliens have succeeded in breeding cows that jump over the moon! Now they want to take home their mutant cows. The aliens want to take all chosen cows back, but their spaceship has a weight limit and they want to minimize the number of trips they have to take across the universe. Somehow, the aliens have developed breeding technology to make cows with only integer weights.
Maggie,3
Herman,7Betsy,9
Oreo,6
Moo Moo,3
Milkshake,2
Millie,5
Lola,2Florence,2Henrietta,9
I don't understand this error message.
I assume that function argument limit=10 refers to the weight that spaceship can take in one flight and 100 is how much weight they want at all.
The aliens have succeeded in breeding cows that jump over the moon! Now they want to take home their mutant cows. The aliens want to take all chosen cows back, but their spaceship has a weight limit and they want to minimize the number of trips they have to take across the universe. Somehow, the aliens have developed breeding technology to make cows with only integer weights.
def load_cows(filename): cow_dict = dict() f = open(filename, 'r') for line in f: line_data = line.split(',') cow_dict[line_data[0]] = int(line_data[1]) return cow_dict def greedy_cow_transport(cows,limit=10): lista = [] totalWeight = 0 scows = sorted(cows) while totalWeight <= limit: for key, value in enumerate(scows): totalWeight += value lista.append(cow) return lista cows = load_cows("ps1_cow_data.txt") limit=100 print(cows) print(greedy_cow_transport(cows, limit)) print(brute_force_cow_transport(cows, limit))error:
Error:Traceback (most recent call last):
File "C:\Python36\kodovi\6.00.2x\ps1.py", line 79, in <module>
cows = load_cows("ps1_cow_data.txt")
File "C:\Python36\kodovi\6.00.2x\ps1.py", line 16, in load_cows
cow_dict[line_data[0]] = int(line_data[1])
ValueError: invalid literal for int() with base 10: '7Betsy'
this is how ps1_cow_data.txt looks like:Maggie,3
Herman,7Betsy,9
Oreo,6
Moo Moo,3
Milkshake,2
Millie,5
Lola,2Florence,2Henrietta,9
I don't understand this error message.
I assume that function argument limit=10 refers to the weight that spaceship can take in one flight and 100 is how much weight they want at all.