Ask coding questions

← Back to all posts
how do I create a function that gives the facts of numbers
AngeloMieses (1)

how do I create a function that gives the facts of numbers

Comments
hotnewtop
AlexanderBirabe (101)
def factorial(n):
  if n == 0:
    return 1
  else:
    return n * factorial(n - 1)
print(factorial(5))

It's under the examples

CalebCarlson (31)

He is asking how to make a function that tells you the attributes of a number, like whether or not its prime or if its even... things like that.
Not a function that returns the factorial of a number.


Also, in line three:

def es primo(num)

Use an underscore (_) to connect those two words.
Here is a better def statement:

def es_primo(num)
SixBeeps (5052)

Do you mean the factorial? As in 7! = 5040 factorial?