Question: Implement the routine numDerangements in python which takes in the number of people in the derangement problem, and returns the number of ways their coats
Implement the routine numDerangements in python which takes in the number of people in the derangement problem, and returns the number of ways their coats can be returned such that no one receives the right coat.
please use the following format:
from math import factorial
# takes in n
# returns the number of possible derangements of n items
# Examples:
# Input Output
#
#
#
#
#
#
#
#
#
#
#
def numDerangements n :
return
# Testing code provided in main:
def main:
testArgs
for arg in testArgs:
nArg, answer arg
result numDerangementsnArg
if result answer:
printfFailed numDerangements test with arg nnArg
Expected: answer Got: result
else:
printfPassed numDerangements test with arg nnArg
return
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
