5. factorial


#1

my code for factorial

import math

def factorial(x):
    user = int(raw_input("Please enter a number: "))
    if(user == 1):
        return 1
    else:
        return user * len(user-1)
        print user

error:
Oops, try again. factorial(1) resulted in an error: invalid literal for int() with base 10: ''

I tried something different. Multiplying the no. entered by user into len(user - 1)
can u let me know where m wrong!


5 Factorial question - why does this code work?
#2

don't use raw_input, and use x the function parameter, the exercises tries if your code works by calling the function with different arguments, so you should use the function parameter (x) of which you should calculate the factorial


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.