import string #importing some useful string methods

"""
check_integer takes a string as input and:
- returns True if the string is a valid representation of an integer
- returns False otherwise
"""
def check_integer(my_string):
    # first check: the only legal characters are the minus sign and the digits.
    for character in my_string:
        if not(character in "-0123456789"):
            return False

    # second check: must have at least one digit.
    if (my_string == "") or (my_string == "-"):
        return False

    # third check: the minus sign is only allowed in the beginning.
    if ('-' in my_string[1:]):
        return False

    #if we did not find any violations, we have a valid integer.
    return True


"""
get_integer takes a text message as an input, and:
- asks the user (by printing the text message) to enter an integer.
- if the user enters a valid integer, we return that.
- otherwise we keep asking the user to enter an integer.
"""
def get_integer(text_message):
    while True:
        text = input(text_message)
        if (check_integer(text) == True):
            return int(text)

