valid numerical string is one with only digits and commas, and commas only appear at every three digits. In addition a valid string only starts with a 0 if it has exactly one character.Python Programming

def valid_format(s):

    """

    Returns True if s is a valid numerical string; it returns False otherwise.

   

    A valid numerical string is one with only digits and commas, and commas only

    appear at every three digits.  In addition, a valid string only starts with

    a 0 if it has exactly one character.

   

    Pay close attention to the precondition, as it will help you (e.g. only numbers

    < 1,000,000 are possible with that string length).

   

    Examples:

        valid_format('12') returns True

        valid_format('apple') returns False

        valid_format('1,000') returns True

        valid_format('1000') returns False

        valid_format('10,00') returns False

        valid_format('0') returns True

        valid_format('012') returns False

   

    Parameter s: the string to check

    Precondition: s is nonempty string with no more than 7 characters

    """

    text=len(s)

    text1= introcs.count_str(s,',')

    if s=='0':

        return True

    if text <=3 and introcs.isnumeric(s):

        return True

    else:

        return False

    pass

Attachments:

Instructions Files

Python Programming Experts

expert
Oliver
Python Programming

60 Answers

expert
Issac Torres
Python Programming

67 Answers

View More Experts
Disclaimer

The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.

Get Free Quote!

250 Experts Online