How to create a list of x characters in python? -


this question has answer here:

i attempting write list "." @ each index many times there supposed rows , columns in game board. code using, error getting telling me cannot multiply sequence non-int of type 'str'. using python 3.5.2.

def mkboard(rows,columns):     board = ["."] * rows * columns     return board  #take user input number of rows , columns board , converts them integers rows = input('enter number of rows:') int(rows) columns = input('enter number of columns:') int(columns)  #create board board = mkboard(rows,columns) 

you're close.

you need assign new int values variables. int() doesn't change variable, return new value.

therefore, proper rows value use:

rows = int(rows) 

and same columns

as aside, should @ how you're generating board. want [[".","."], [".", "."]] 2x2 board. advise @ list comprehensions


Comments