Question
#MODIFY THE TEMPLATE TO: Recall the grids from previous chapters. #Write code that gets a width and height from the user, and returns a #two
#MODIFY THE TEMPLATE TO: Recall the grids from previous chapters. #Write code that gets a width and height from the user, and returns a #two dimensional list, where each element is a string representation #of the coordinates of that tile. PLEASE NOTE: ONLY use the len() and/or append() functions for this problem.
ONE MORE NOTE: Here is the row and column formulas if we want to find out what they might be based upon a given tile number for a grid of any dimensions, whether its 3X3, or 4X7, etc.
row = (tile - 1) // width col = (tile - 1) % width import subprocess #from answer import * import sys #print sys.argv[0] def template(w,h): width = w height = h return [[]] #END OF YOUR CODE failed = False w = 1 while w <= 3: h = 1 while h <= 3: result = [] row = 0 while row < h: col = 0 inner = [] while col < w: inner.append("("+str(col)+","+str(row)+")") col += 1 result.append(inner) row += 1 if template(w,h) == result: print "you got it RIGHT!" else: print "for width:"+str(w) +" height:"+str(h)+" we expected "+str(result)+", but you got: " + str(template(w,h)) failed = True h += 1 w += 1 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 failed == False: print "Your code is CORRECT!"
else: print "Please check your code, at least one test case did not pass."
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