fork download
  1. def reverse_factorial(num):
  2. try:
  3. float(num)
  4. except:
  5. return None
  6. i = 2
  7. if num == abs(num):
  8. j = 1
  9. else:
  10. j = -1
  11. num = abs(num)
  12. while num > 1:
  13. num /= i
  14. i += 1
  15. return j*i-1 if num == 1 else None
  16.  
  17. for num in [3628800,479001600,6,18,"a",1.2,-24]:
  18. rev_fac = reverse_factorial(num)
  19. print(num," NONE") if rev_fac is None else print(num," = ",rev_fac,"!",sep="")
Success #stdin #stdout 0.01s 9992KB
stdin
Standard input is empty
stdout
3628800 = 10!
479001600 = 12!
6 = 3!
18  NONE
a  NONE
1.2  NONE
-24 = -6!