Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def chicken_rabbit(num_heads, num_legs):
- lowest_num_legs = num_heads * 2 # Lowest possible amount of legs
- difference = num_legs - lowest_num_legs
- num_one = difference / 2
- num_two = num_heads - num_one
- return num_two, num_one
- def unittest_function_pass():
- # write assertion statements here to test the function
- # enumerate as many test cases you can think of to test your function
- # See "Additional Requirements described in the assignment" for details.
- listB = []
- listB = chicken_rabbit(31, 94)
- assert(listB[0] > 0)
- return
- def unittest_function_xfail():
- # write assertion statements here to test the function on any expected failing cases
- # See "Additional Requirements described in the assignment" for details.
- listA = []
- listA = chicken_rabbit(7, 56)
- assert(listA[0] > 0)
- return
- if __name__ == "__main__":
- num_heads = int(input("Input number of heads:\n"))
- num_legs = int(input("Input number of legs:\n"))
- n_chicken, n_rabbit = chicken_rabbit(num_heads, num_legs)
- if (n_chicken < 0 or n_rabbit < 0):
- print("Invalid inputs received. Program aborted.")
- else:
- if n_chicken == 1:
- print("There is 1 chicken in the cage")
- elif n_chicken == 0:
- print("There isn't any chicken in the cage")
- else:
- print("There are %d chickens in the cage" % n_chicken)
- if n_rabbit == 1:
- print("There is 1 rabbit in the cage")
- elif n_rabbit == 0:
- print("There isn't any rabbit in the cage")
- else:
- print("There are %d rabbits in the cage" % n_rabbit)
- # TODO: complete the unittest_function so your function undergo a rigorous unittest created by yourself
- unittest_function_pass()
- # TODO: complete the unittest_function_xfail so your function undergo a rigorous unittest created by yourself
- # Please note that unittest_function_xfail is ALWAYS expected to trip an error! Because it is testing on expected failing cases
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement