5. factorial


I am trying to use result = ' * '.join(str(result_list)), but it isn't working! My code is listed below:

def factorial(x):
    result_list = list(range(x, 0, -1))
    result = ''
    for number in range(len(result_list)):
        result = ' * '.join(str(result_list))
    print result



simple question: why? What do you think it does?

I am trying to grasp the logic of your code, but i am not sure i do. I find it very clever you make a list:

result_list = list(range(x, 0, -1))

that is really good. but "".join() is for joining a list into a string, is that really what you want?

I would declare a variable total, set it to one, and then multiply it with all values in your list


I want to convert it into a string because then I can eval the string


But thats also a good idea... Ill try it


as for your string solution, you could make an empty string. then loop over result_list and add each value to the string. don't forget to cast the integer to a string


Yeah. Thanks. Ill try that too


Thanks a lot for the fast reply


Did you already figure out? That was fast


You can use the join method for this exercise, but it is a bit awkward.

If you create a list of numbers represented as strings, you can call the join method from "*" to create a unified string, and then pass that to the eval function. The embedded "*" characters will function as * operators. However, if you plan on using range to construct your list, you must account for the fact that the factorial of 0 and the factorial of 1 are each 1.


Thanks @appylpye appylpye for helping


Really? I thought I was pretty slow in learning what the problem was
EDIT: Thanks for what you said below


some people can't figure it out when you give a hint like that. You did really good :slight_smile: