scorpious
April 24th, 2011, 11:14 PM
I posted this question in absolute beginner talk but should probably have posted it here.
anyway here's my programme
def start():
size = (raw_input("Board size: "))
number = ['2','3','4','5','6','7','8','9']
while size not in number:
print 'must be between 2 and 9'
size = (raw_input("Board size: "))
size = int(size)
return size
def set_up(n):
row = []
grid = []
count = 0
while count != n:
row.append('.')
count += 1
count = 0
while count != n:
grid.append(row)
count += 1
return grid
def assign_numbers(grid):
print grid
list = grid
count = 0
number = len(list) - 2
start = 3
while count <= number:
list [count][0] = start
print list
count += 1
start = start - 1
return list
def assign_letters(grid):
print grid
new_list = grid[-1]
number = len(new_list)
letters = ['.','a','b','c','d','e','f','g','h']
letters = letters[0:number]
grid[-1] = letters
print grid
grid_size = start()
grid1 = set_up(grid_size)
grid2 = assign_numbers(grid1)
grid3 = assign_letters(grid2)
print grid3when I input '4' I expected it to print
[['3', '.', '.', '.'], ['2', '.', '.', '.'], ['1', '.', '.', '.'], ['.', 'a', 'b', 'c']]but the assign_numbers function is giving me grief and i get
[['1', '.', '.', '.'], ['1', '.', '.', '.'], ['1', '.', '.', '.'], ['.', 'a', 'b', 'c']]can anyone tell me why it returns a whole bunch on 1s?
cheers
Tom
anyway here's my programme
def start():
size = (raw_input("Board size: "))
number = ['2','3','4','5','6','7','8','9']
while size not in number:
print 'must be between 2 and 9'
size = (raw_input("Board size: "))
size = int(size)
return size
def set_up(n):
row = []
grid = []
count = 0
while count != n:
row.append('.')
count += 1
count = 0
while count != n:
grid.append(row)
count += 1
return grid
def assign_numbers(grid):
print grid
list = grid
count = 0
number = len(list) - 2
start = 3
while count <= number:
list [count][0] = start
print list
count += 1
start = start - 1
return list
def assign_letters(grid):
print grid
new_list = grid[-1]
number = len(new_list)
letters = ['.','a','b','c','d','e','f','g','h']
letters = letters[0:number]
grid[-1] = letters
print grid
grid_size = start()
grid1 = set_up(grid_size)
grid2 = assign_numbers(grid1)
grid3 = assign_letters(grid2)
print grid3when I input '4' I expected it to print
[['3', '.', '.', '.'], ['2', '.', '.', '.'], ['1', '.', '.', '.'], ['.', 'a', 'b', 'c']]but the assign_numbers function is giving me grief and i get
[['1', '.', '.', '.'], ['1', '.', '.', '.'], ['1', '.', '.', '.'], ['.', 'a', 'b', 'c']]can anyone tell me why it returns a whole bunch on 1s?
cheers
Tom