Python Practice Lab
easyUnit 8 · Functions, Callbacks & lambda

P22. Factorial and Combinations

Functions, Callbacks & lambda

Write a function factorial(n) that uses a loop to return n!. Then use it to find nCr = n! / (r! × (n − r)!).

Input Format

  • Line 1: n
  • Line 2: r

Output Format

  • Line 1: <n>! = <value>
  • Line 2: <n>C<r> = <value>

Constraints

  • 0 ≤ r ≤ n ≤ 20
  • Do not use the math module

Sample Test Cases

Sample 1
Input
5
2
Output
5! = 120
5C2 = 10
Sample 2
Input
10
0
Output
10! = 3628800
10C0 = 1

Submitting checks 2 sample cases and 3 hidden test cases.

Hints

Saved
Custom 1

This is your own input, so Run will show what your program prints but can't say whether it's correct.