File tree
Expand file treeCollapse file tree1 file changed
+33
-0
lines changed Expand file treeCollapse file tree1 file changed
+33
-0
lines changed Original file line number | Diff line number | Diff line change |
---|
|
| 1 | +#lex_auth_012693810762121216155 |
| 2 | + |
| 3 | +def solve(heads,legs): |
| 4 | +error_msg="No solution" |
| 5 | +chicken_count=0 |
| 6 | +rabbit_count=0 |
| 7 | + |
| 8 | +#Start writing your code here |
| 9 | +#Populate the variables: chicken_count and rabbit_count |
| 10 | + |
| 11 | +if legs%2 != 0 or heads > legs: |
| 12 | +print(error_msg) |
| 13 | +return |
| 14 | + |
| 15 | +# heads: x + y = a |
| 16 | +# legs: x + 2y = b/2 (sub) |
| 17 | +# ------------ |
| 18 | +# y = b/2-a |
| 19 | + |
| 20 | +# from eq 1: x = a - y |
| 21 | + |
| 22 | +rabbit_count = legs//2 - heads |
| 23 | +chicken_count = heads - rabbit_count |
| 24 | +print(chicken_count,rabbit_count) |
| 25 | + |
| 26 | +# Use the below given print statements to display the output |
| 27 | +# Also, do not modify them for verification to work |
| 28 | + |
| 29 | +#print(chicken_count,rabbit_count) |
| 30 | +#print(error_msg) |
| 31 | + |
| 32 | +#Provide different values for heads and legs and test your program |
| 33 | +solve(38,131) |
You can’t perform that action at this time.
0 commit comments