Python edabit Challenge : The Farm Problem

preview_player
Показать описание
In this challenge, a farmer is asking you to tell him how many legs can be counted among all his animals. The farmer breeds three species:

chickens = 2 legs
cows = 4 legs
pigs = 4 legs
The farmer has counted his animals and he gives you a subtotal for each species. You have to implement a function that returns the total number of legs of all the animals.

def animals(chickens, cows, pigs):
totalchickens = chickens * 2
totalcows = cows * 4
totalpigs = pigs * 4
return totalchickens + totalcows + totalpigs
Рекомендации по теме
Комментарии
Автор

Your solution is correct but there are two alternative solutions that I know
# First Solution
def animals(chickens, cows, pigs):
return chickens * 2 + cows * 4 + pigs * 4

# Second Solution
animals = lambda chickens, cows, pigs: chickens * 2 + cows * 4 + pigs * 4

Suvin_Chin