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

#Trying to create a simple while loop that uses a #pre-stored width #and height

ID: 3731638 • Letter: #

Question

#Trying to create a simple while loop that uses a #pre-stored width

#and height to return a string of all of the coordinates of each

#tile in the grid, in order, separated by spaces.

import subprocess

def template(w,h):

width = w

height = h

result = "1"

return result

#END OF YOUR CODE

print "For a 3x4 board,"

result = ""

h = 0

while h < 4:

w = 0

while w < 3:

result += "("+str(w)+","+str(h)+") "

w += 1

h += 1

if template(3,4) == result or template(3,4) == result[:-1]:

print "you got it RIGHT!"

result = subprocess.check_output

else:

print "we expected '" + result + "', but you got: " + str(template(3,4))

result = subprocess.check_output

Explanation / Answer

The question u have asked is little confusing. You did not specify what has to be done to ths question. As u have already created a while loop required. if you are getting any error with this question then i would suggest to check your indendation properly.

def template(w,h):

width = w

height = h

result = "1" //indentation need to be done properly here.

return result

if this is not the issue you are facing then i would assume the problem is the coding part. This program runs perfectly with proper indendation but it only prints the else condition so i assume that the problem here is that you are not able to execute the if condition that is given in the your program.

this is the output i assume u are getting right now! to gett all the point on the list including the boundary points you might alter the code like this:

print "For a 3x4 board,"

result = ""

w = 0

while w <= 3:

h = 0

while h <= 4:

result += "("+str(w)+","+str(h)+") "
  

h += 1

w += 1

which gives output

I did not understand the logic of your function as it serves no required purpose. here is how you can change it to get the if condition

def template(w,h):

width = w
height = h
  
result = ""
for y in range(0,int(width+1)):
for x in range(0,int(height+1)):
result += "("+str(y)+","+str(x)+") "
  
return result

#END OF YOUR CODE

print "For a 3x4 board,"

result = ""

w = 0

while w <= 3:

h = 0

while h <= 4:

result += "("+str(w)+","+str(h)+") "
  

h += 1

w += 1

if template(3,4) == result or template(3,4) == result[:-1]:

print "you got it RIGHT!"

result = subprocess.check_output

else:

print "we expected '" + result + "', but you got: " + str(template(3,4))

result = subprocess.check_output
  

output:

I hope i solved your problem