""" A simple program, that gets an integer from the user, and prints the result of multiplying that integer by 2. The program reports an error message if the user did not enter an integer. """ text = input("please enter an integer: ") text = text.strip() # found_violation will be set to True the moment we find a violation # of the integer format. found_violation = False # first check: the only legal characters are the minus sign and the digits. for character in text: if not(character in "-0123456789"): found_violation = True print("found non-digit character:", character); break # second check: must have at least one digit. if (text == "") or (text == "-"): found_violation = True print("This string does not contain any digits.") # third check: the minus sign is only allowed in the beginning. if ('-' in text[1:]): found_violation = True print("The minus sign is only allowed at the beginning.") #if we did not find any violations, we have a valid integer. if (found_violation == False): number = int(text) print(number * 2)