I would like the "ValueError" to appear when the function is called with a float number. But I get
an error message saying that float numbers are not allowed.

import math
def factorial(number):
    if number>=0 and type(number)!=float(number):
        return fact
        return ValueError
print factorial(1)
print factorial(0)
print factorial(9)
print factorial(2.5)

Replace this line with your code.


you should check if type does not equal float:


what you did, will convert input to a float number, and then check if float type not equals float number


Sorry, I don't understand what you mean.


i literally give you the code?

there is a problem with your condition. lets say we have 2.5, you have the following condition:

type(2.5) != float(2.5)

which results in:

float != 2.5

this condition is true. Instead, you want to see if type of number equals float data type:


which would result in:

type(2.5) != float
float != float

which is false, else will run (as you want to achieve)


Thanks. I changed it, and works as I intended.