Ad
Algorithms
Logic
Mathematics
Numbers

Recursion based implementations are not a great idea to count factorials. :)

Code
Diff
  • def factorial(x):
        result = 1
        for i in range(2, x + 1):
            result *= i
        return result
    
    • def factorial(x):
    • return x * factorial(x-1) if x > 0 else 1
    • result = 1
    • for i in range(2, x + 1):
    • result *= i
    • return result
Algorithms
Logic
Mathematics
Numbers

The variable x can be from 0 to +∞.

Code
Diff
  • def factorial(x):
        result = 1
        for i in range(2, x+1):
            result *= i
        return result
    
    • def factorial(x):
    • return 1 if x == 1 else x*factorial(x-1)
    • result = 1
    • for i in range(2, x+1):
    • result *= i
    • return result
Code
Diff
  • # caesar cipher shifted of 13 characters with maketrans for python 2.7
    from string import maketrans as mktr, ascii_uppercase as asuc
    
    def caesar(s):
        return s.translate(mktr(asuc, asuc[13:] + asuc[:13]))
    
    • # caesar cipher shifted of 13 characters with maketrans for python 2.7
    • from string import maketrans
    • import string
    • from string import maketrans as mktr, ascii_uppercase as asuc
    • def caesar(s):
    • print(s)
    • s=s.translate(maketrans(string.ascii_uppercase, string.ascii_uppercase[13:]+string.ascii_uppercase[:13]))
    • return s
    • return s.translate(mktr(asuc, asuc[13:] + asuc[:13]))