Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(USING PYTHON 2.7) To complete this assignment you may find the following inform

ID: 3833664 • Letter: #

Question

(USING PYTHON 2.7)

To complete this assignment you may find the following information useful: List.split() # splits on white space List.split(('-') # splits on a hyphen Compound logic: Use if true and true to enforce two conditions Cast a string to an int: int(aString) Use for loop to iterate over the contents of a container Use try - except to identify bad data Ask the user to enter an ip address If you store it in a list it may look like this ['123', '12', '33', '0'] You need access to the numbers inside the quotes - change them inside the list [123,12, 33, 0] Or change them one-by-one as you examine them Determine that each portion of the address is correct Your application should correctly handle the following sample data: Sample data 123.12.1.55 # Valid 123.234.345.123 ft Invalid - 345 > 255 lq.88.222.17 # Invalid - Non-numeric character 127.0.0.0 # Valid

Explanation / Answer

s = raw_input("Enter a ip address:")
lt = s.split('.')
hat = 0
try:
   for i in range(0,4):
       lt[i] = int(lt[i])
       if(lt[i]>255):
           print("#Invalid-"+str(lt[i])+" > 255")
           exit()
except ValueError:
   print("#Invalid - Non-numeric character")
   exit()
print("#Valid")