Answered step by step
Verified Expert Solution
Link Copied!

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 >=1
# returns the number of possible derangements of n items
# Examples:
# | Input | Output |
# |---------|----------|
# |1|0|
# |---------|----------|
# |2|1|
# |---------|----------|
# |3|2|
# |---------|----------|
# |4|9|
# |---------|----------|
# |5|44|
# |---------|----------|
def numDerangements( n ):
return 0
# Testing code provided in main():
def main():
testArgs =[[1,0],[2,1],[3,2],[4,9],[5,44]]
for arg in testArgs:
nArg, answer = arg
result = numDerangements(nArg)
if result != answer:
print(f"Failed numDerangements test with arg n={nArg}.
Expected: {answer}, Got: {result}")
else:
print(f"Passed numDerangements test with arg n={nArg}.")
return 0
if __name__=='__main__':
main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

=+3 In what ways can an MNE improve or change its approach to IHRM?

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago