Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started