Day 057 - Project 57 : Factorial Calculator

If you have any questions, comments or issues with this project please post them here!

I think the example in the challenge for day 57 is misleading… it shows that here should be an input in the solution but when I go to David’s answer it’s not needed. I also tried to use his code to allow an input but it wasn’t working. Do you know how I could have done that? Thanks in advance!

@laurenjane I just finished this lesson and saw you never got a reply to your question. Here is my code that takes user input of the number to find the factorial of. Hope this answers your question if i misunderstood apologizes

def recursion(value):
  if value <= 1:
    return value
    return(value * recursion(value - 1))

print("🌟Factorial Finder🌟")
fractal = int(input("Enter a number: > "))
print(f"The factorial of {fractal} is {recursion(fractal)}")

Your response made a ton of sense and helped me understand this simple concept more. I tend to overthink things and your code was straightforward!

1 Like

I want to make the function return a variable (result) that I can print in the solution.
Why is it not working? :sob:

def factorial(value):
  if value <= 1:
    return value
    result = value * factorial(value-1)
    return result

value = int(input("Input a number > "))
print(f"The Factorial of {value} is {result}.")

The error I get is that result is not defined !?

Result is only in scope of the elke in the function. This means it is only declares in the else and as such not visible outside of it. But you return it so… this should tell you where your error is without me writing code :slight_smile:


omg! so simple haha
thank you ^.^