Create a function with signature:
integer(number)
The number parameter is either a number or a string that can be converted to
a number. The function should return the number as type int, rounding it if
the number passed in is a float. If the conversion fails, catch the
ValueError exception, and return 0. Make sure it works for both strings and
literal numbers, such as 4.5, 32, "23", and "-15.1", and that it correctly returns
zero for invalid numbers like "tonsils". This can be done in half a dozen lines.
(Hint: To work with all the cases you'll always need to convert to type float
first.)
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here