+ 13
Factorial CHALLANGE
Hi! This challenge is about factorial operation. This is then your number starting multiply it self from one to it self. like: 5! = 1*2*3*4*5 = 120 or 6! = 1*2*3*4*5*6 = 720 Write a calculator or something like i did in other languages. https://code.sololearn.com/Wo2A2Zg0cFMP/?ref=app
31 Antworten
+ 7
Recursive Lambda
https://code.sololearn.com/cb60vmKFbNLk/?ref=app
Non-Recursive
https://code.sololearn.com/cspGL8hL6tQk/?ref=app
Non-Recursive Lambda with eval (oneliner) ***BEST***
https://code.sololearn.com/cTL9Erz40lhW/?ref=app
+ 26
https://code.sololearn.com/cPPGIaXLb8e7/?ref=app
+ 23
https://code.sololearn.com/cha99rgulGmE/?ref=app
+ 15
https://code.sololearn.com/cp1UNm7yaxMu/?ref=app
+ 12
https://code.sololearn.com/c9U7NM6WT8q4/?ref=app
+ 10
https://code.sololearn.com/cu8uHv5XB2RR/?ref=app
+ 8
https://code.sololearn.com/ceaw76y9q4jz/?ref=app
+ 8
Ruby:
(1..n).inject(:*) || 1
https://code.sololearn.com/cJXhhv3Thov2/
edit: code has been corrected so it also returns the right answer when negative numbers are given
+ 6
my try :)
https://code.sololearn.com/cV9p8IOnjtCM/
EDIT:
V2 different approach, sould be much faster :)
https://code.sololearn.com/chgx5Y8uV971/
+ 5
Most simply:
from math import factorial
print(factorial(int(input())))
Or written out for clarity, a recursive function:
Simple Factorial
https://code.sololearn.com/cwiswHNQz0lE/?ref=app
Remember that 0! = 1 and negative factorial is undefined. Many of the other programs return these two conditions incorrectly.
+ 4
https://code.sololearn.com/cghCd97518YH/?ref=app