0 out of 464 challenges solved
Write a Python function `is_decimal` that checks whether a given string represents a decimal number with a precision of up to 2 decimal places. The function should return `True` if the string is a valid decimal number with at most two digits after the decimal point, and `False` otherwise. #### Requirements: - The input will be a string. - A valid decimal number can have: - Only digits (e.g., `"123"` is valid). - A decimal point followed by up to two digits (e.g., `"123.45"` is valid). - No leading or trailing spaces. - No additional characters or multiple decimal points. #### Examples: ```python [main.nopy] is_decimal("123.11") # True is_decimal("e666.86") # False is_decimal("3.124587") # False is_decimal("1.11") # True is_decimal("1.1.11") # False ``` Implement the function to meet these requirements.
def is_decimal(num: str) -> bool: """ Check if the given string is a valid decimal number with up to two decimal places. Args: num (str): The string to check. Returns: bool: True if the string is a valid decimal number, False otherwise. """ # Import the regular expression module import re # Define the regular expression pattern for a valid decimal number # Placeholder for the solution # Return the result of the match return False