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

help in python def read_board(s): Given a string containing lines of either play

ID: 3600928 • Letter: H

Question

help in python

def read_board(s): Given a string containing lines of either player pieces or periods, pick apart the string and generate the corresponding board. Blank lines must be ignored, but if the non-blank lines dont create a rectangular shape (different lines have different lengths) or if other characters show up (neither periods nor upper-case letters), return None instead of a generated board. Assume: s is a string. • Reminder: only periods and upper-case letters are in valid boards, and valid boards are always rectangularYou must check both of these! • read_board"... ABA ") — [['.', '.', '.'],['A', 'B', 'A']] • read_board (".. . . OK ") ['.', '.'], [.', '.'], ['o ', 'K']] • read_board (".... . .[nN00 ") — None #different-length rows def get_size(board): Given a board, find the dimensions and return as a tuple: (numrows, numcols) Assume: board is a valid board. • get_size (['', '', ''], [ .', '', '')) (2,3) • get_size (ex3) (5,4) def is_valid_coord (board, r, c): Given a board and two ints, do r and c describe a valid location on the board? Negative indexes are not allowed here (as a design decision). • Assume: board is a valid board, r and c are integers. • Hint: you should be using this function all over the place in the rest of your project! • is_valid_coord((( "B",":", "R"1. [ "R", "R", "B"), , ) True • is_valid_coord(("B" ,":", "R"],[ "R", "R", "B")1, 2, 3) False is_valid_coordC "B" ,"1", "R"],[ "R' ", "R", "B"), -1,-1) False

Explanation / Answer

def read_board(s):
    a=s.split(" ")
    a=a[0:len(a)-1]
    b=[]
    i=0
    l=0
    f=0
    print a
    while i<len(a):
        if i==0:
            l=len(a[i])
            b.append(list(a[i]))
        else:
            if len(a[i])!=l:
                f=1
                return None
                break
            else:
                b.append(list(a[i]))
        i+=1
    return b

def get_size(board):
    a=(len(board),len(board[0]))
    return a

def is_valid_coord(board,r,c):
    if r<=len(board) and c<=len(board[0]):
        return True
    else:
        return False