Translate to Traditional Chinese (δΈ­ζ–‡):

<< Prev   🏠 A B C D E F G Next >>


G.py - Let's Count Animals

Problem Description:
A farmer has a mix of chickens and dogs on his farm. He knows the total number of animals and the total number of legs, but he isn't sure how many of each he has.
Please help the farmer determine the exact number of chickens and dogs based on this information.
Remember: Chickens have 2 legs and Dogs have 4 legs

Task:
Write a program that asks user to enter two interger number: The total number of animals (Dogs and Chickens) total_animals and the total number of legs total_legs
Your program should calculate the number of dog and the number of chicken and display the result on the screen as the examples bellow.

Hint:
total_animal = dog + chicken
total_leg = 4*dog + 2*chicken
Solve these fomulars you will get the number of dog and chicken.

Don't worry if the number of dogs and chickens is not a whole number. We will address this issue later in the If-Else lecture.


Example 1:
Enter number of total animals: 10
Enter number of total legs: 28
Chickens: 6
Dogs: 4
Explanation: Total animals = 6 + 4 = 10 and total legs = 6 x 2 + 4 x 4 = 28

Example 2:
Enter total animals: 12
Enter total legs: 32
Chickens: 8
Dogs: 4
Explanation: Total animals = 8 + 4 = 12 and total legs = 8 x 2 + 4 x 4 = 32


<< Prev   🏠 A B C D E F G    Next >>