Python: Factorial of a number using itertools module
Python Itertools: Exercise-20 with Solution
Write a Python program to find the factorial of a number using the itertools module.
import itertools as it import operator as op def factorials_nums(n): result = list(it.accumulate(it.chain(, range(1, 1 + n)), op.mul)) return result; print("Factorials of 5 :", factorials_nums(5)) print("Factorials of 9 :", factorials_nums(9))
Factorials of 5 : [1, 1, 2, 6, 24, 120] Factorials of 9 : [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program which iterates the integers from 1 to a given number and print "Fizz" for multiples of three, print "Buzz" for multiples of five, print "FizzBuzz" for multiples of both three and five using itertools module.
Next: Write a Python program to find the years where 25th of December be a Sunday between 2000 and 2150.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join