From b6fc6b7599dcccf5fb465becb687a81841ce5f6b Mon Sep 17 00:00:00 2001 From: go1337 Date: Fri, 14 Oct 2022 17:27:24 +0300 Subject: [PATCH] Update Day 1.md 1-updated question 2 description, it is a single number, not multiple. 2-Removed the comma separation thing, if it's only one number, it's not needed. 3-added a solution for question 2 that actually uses lambda function, the one from harshraj22 does NOT use a lambda function 4- modified the title for harshraj22's solution to normal function, there is no lambda there --- Status/Day 1.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Status/Day 1.md b/Status/Day 1.md index 557714e..1e3f28e 100644 --- a/Status/Day 1.md +++ b/Status/Day 1.md @@ -46,7 +46,7 @@ print(*(i for i in range(2000, 3201) if i%7 == 0 and i%5 != 0), sep=",") ### **Question:** -> **_Write a program which can compute the factorial of a given numbers.The results should be printed in a comma-separated sequence on a single line.Suppose the following input is supplied to the program: 8 +> **_Write a program which can compute the factorial of a given number. Suppose the following input is supplied to the program: 8 > Then, the output should be:40320_** --- @@ -93,7 +93,7 @@ print fact(x) fact = fact * i print(fact) ``` -- **Using Lambda Function** +- **Using a Function** ```python # Solution by: harshraj22 @@ -136,6 +136,20 @@ print(reduce(fun,range(1, num+1), 1)) ``` --- +- **Using Lambda Function and Reduce** +```python +'''Soltuion by: go1337 +''' +from functools import reduce + +input_nr = int(input("Enter number to get its factorial: ")) + +factorial = reduce(lambda x, y: x * y, range(1, input_nr + 1)) +print(factorial) +``` +--- + + # Question 3 ### **Question:**