Question
MY last question wasn't answered, and I'd appreciate some help!! #MODIFY THE TEMPLATE TO : Write code that walks over a two dimensional #list of
MY last question wasn't answered, and I'd appreciate some help!!
#MODIFY THE TEMPLATE TO: Write code that walks over a two dimensional #list of integers, and checks to see if a neighbor of an element #(so to its right or left) is negative; if so, it returns a string containing #all pairs in parentheses of the (neighbor,current element) separated by spaces. #For example, the list [[1,-2],[],[-1,-2,-3,4]] would be returned as the string # (-2,1) (-2,-1) (-1,-2) (-3,-2) (-2,-3) (-3,4) import subprocess #from answer import * import sys def template(l1): list1 = l1 return "(0,0)" #END OF YOUR CODE test1 = template([[1,-2],[],[-1,-2,-3,4]]) source = open(sys.argv[0],"r") lines = source.readlines() source.close() ctr = 1 Failed = False while ctr < len(lines) and lines[ctr][:-1] != 'source = open(sys.argv[0],"r")': line = lines[ctr] if ('(".index(" in line or ".rindex(" in line' not in line) and (".index(" in line or ".rindex(" in line or ".remove(" in line or ".count(" in line or ".find(" in line or ".split(" in line or ".rsplit(" in line or ".rindex(" in line or ".join(" in line or "sorted(" in line or "min(" in line): print "ERROR: on line " +str(ctr) + ": "+ line + " you are using a forbidden function or method. You are only allowed to use len(...) and/or .append(...) for this assignment." Failed = True ctr += 1 if not Failed and test1 == "(-2,1) (-2,-1) (-1,-2) (-3,-2) (-2,-3) (-3,4)" or test1 == "(-2,1) (-2,-1) (-1,-2) (-3,-2) (-2,-3) (-3,4) ": print "you got it CORRECT!" else: print "for [[1,-2],[],[-1,-2,-3,4]] we expected '(-2,1) (-2,-1) (-1,-2) (-3,-2) (-2,-3) (-3,4)', but you got: " + str(test1)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started