所以我已經成功地創建可用於創建具有可配置的行和列的棋盤程序:獲取函數返回,而不是打印
def print_column_labels():
print " a b c d e f g h"
def print_separator_row(num_columns):
print " " +"+-" * num_columns+"+"
def print_squares_white(row_number, num_columns):
if row_number<=9:
print " "+str(row_number) +" "+"| |#" * (num_columns/2)+"| "+str(row_number)
else:
print " "+ str(row_number) +""+"|#| " * (num_columns/2)+"| "+str(row_number)
def print_squares_black(row_number, num_columns):
if row_number<=9:
print " "+ str(row_number) +" "+"|#| " * (num_columns/2)+"| "+str(row_number)
else:
print " "+ str(row_number) +""+"|#| " * (num_columns/2)+"| "+str(row_number)
def print_chessboard(row_num,num_columns):
print_column_labels()
print_separator_row(num_columns)
if row_num%2==0:
while row_num>=1:
print_squares_white(row_num,num_columns)
row_num-=1
print_separator_row(num_columns)
print_squares_black(row_num,num_columns)
row_num-=1
print_separator_row(num_columns)
if row_num==0:
print_column_labels()
else:
while row_num>=2:
print_squares_white(row_num,num_columns)
row_num-=1
print_separator_row(num_columns)
print_squares_black(row_num,num_columns)
row_num-=1
print_separator_row(num_columns)
if row_num==1:
print_squares_white(row_num,num_columns)
print_separator_row(num_columns)
print_column_labels()
,我需要能夠在接下來的事情與該程序相關的是將其從打印板改爲將其作爲字符串返回。我如何去改變代碼?
,而不是'print',使用'return' –
我試圖取代我到處使用'和'return' print',但我得到的'的輸出中none' – user2843355
你如何使用該功能得到'None'的輸出? – SethMMorton