I am not sure whether to use try/except or an if condition to detect whether a number is an int or a float. I know my input is either a float or an int, and I want to raise a value error for all floats, and do something if the number is an int. An example of where this type of behavior might be seen is a factorial... However, I don't want a 5.0 to be converted to a 5. What is the best approach?
factorial(5)
> 120
factorial(asdf)
> ValueError
factorial(5.0)
> ValueError
I read this question Parse String to Float or Int but I am still confused
factorialnot caring about type of input, it will probably (a) work for types which make sense, and (b) raise an execption for other types anyway.factorialfunction are you talking about? Is it one you've written?math.factorialbut a good question all the samemath.factorialdoesn't raise a ValueError with5.0. I was hoping to prod OP into an example that has something to do with his problem.