Question: I need help writing two different functions in python. Python only please! The first function - Write a function named digit_count that takes one parameter
I need help writing two different functions in python. Python only please!
The first function -
Write a function named digit_count that takes one parameter that is a number (int or float) and returns a count of even digits, a count of odd digits, and a count of zeros that are to the left of the decimal point.
Return the three counts in that order: even_count, odd_count, zero_count.
Be careful of the edge case where the number starts with a decimal pointconversion of such a number to a string places a zero before the decimal point.
See correct behavior in the final test case below.
For example:
digit_count(1234567890123)
returns (5, 7, 1)
digit_count(123400.345)
returns (2, 2, 2)
print(digit_count(123.))
returns (1, 2, 0)
print(digit_count(.123))
returns (0, 0, 0)
The second function -
Write a function named float_check that takes one parameter that is a string and returns True if the string represents a float and False otherwise. For this function we define a float to be a string of digits that has at most one decimal point. Note that under this definition an integer argument will return True. Remember edge cases such as 45. or .45; both should return True.
For example:
float_check('1234')
returns True
float_check('123.45')
returns True
float_check('123.45.67')
returns False
float_check('34e46')
returns False
float_check('.45')
returns True
float_check('45.')
returns True
float_check('45..')
returns False
Need help writing those two functions as described in python. Thank you in advance for any help.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
