计算机代考 COMP1730/6730 Homework 2 The problem

COMP1730/6730 Homework 2 The problem
Calculating the number of ways to select k distinct elements from a set of n is one of the most
famous problems in combinatorics. This number is often called “n choose k”, or the binomial
coefficients. We will call it combinations(n, k), because you will implement it in a function called

Copyright By PowCoder代写 加微信 powcoder

combinations
There are several ways to compute this number, but the one that most students find easiest is the
k!(n – k)!
where n! is the factorial function of n. The factorial of O is defined to be 1, so that the combinations
formula still works when n or k are zero.
Your task is to write a function combinations (n, k) that computes and returns the n choose k, or
combinations(n, k), number.
The function must take two arguments (that is, have two parameters), and it must return an integer
value (a value of type int)
We provide you with a skeleton code file: combinations. py. Download this file and write in it your
implementation of the function.
The skeleton file already has in it several functions: One is an implementation of the factorial function,
which you can use in your combinations function. (Note that there is also a function called factorial
in the math module, which you can also use.) The others are testing functions that you can (and
should!) use to test if your function is working correctly.

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com