printBoard: A call to this function with

printBoard(5,4,[1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])

would print the following output to standard output:

|-----------|
| 1 0 0 1 0 |
| 0 0 0 0 0 |
| 0 0 0 0 0 |
| 0 0 0 0 0 |
|-----------|

def board(l,h,list): %a length, and a height, and a single list of integers/strings,
board =rawinput();

Recommended Answers

All 4 Replies

You did not post what you have done and what is your current specific problem.

printBoard: This function will expect as input a single list of integers, a length, and a height, and a single list of integers/strings, in that order. The code will output the contents of the board with the formatting described further below, or print Invalid board! if the board does not match the length and height, or the contents of the board are not integers and/or strings. The length of each elements in the board, printed as characters, will always be 1.

def function(length, height, list):
lenght=0
height=0
list=()

board= rawinput()

Isn't "a boad" a place where you live (sorry couldn't pass that up). An easy to understand example follows. You will have to substitute the variable for the hard-wired ">", and come up with some decent code to input things, as well as

"or print Invalid board! if the board does not match the length and height, or the contents of the board are not integers and/or strings"

as you haven't even made a decent attempt. Your code is not properly indented and will give an error on the "board= rawinput()" statement. "Thinking in Python" has a section on keyboard input and converting input to integers.

test_list=[1,0,0,1,0,0,2,0,0,0,0,0,3,0,0,0,0,0,4,0]
ctr=0
for item in test_list:
    print item,
    ctr += 1
    if ctr > 4:
        ctr=0
        print
print
#
# you can also do it with 2 for() loops
for out in range(0, len(test_list), 5):
    for inner in range(5):
        print test_list[out+inner],
    print

thats the part i dont understand how to do the input, help me please.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.