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...



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.)



May 26, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here