次のような星でできたボックスに単語を出力するプログラムを作成しています。
************
* *
* danielle *
* *
************
ただし、次の出力が得られます。
************
*
None *
* danielle *
*
None *
************
と関数を同じ行に出力できないためprint
、「なし」の出力が得られ続けることはわかっています。string
どうすればこれを行うことができますか?
私のコードは次のとおりです。
def star_str(length):
stars = '*'*length
print stars
def spaces_str(length):
spaces = " "*length
print spaces
def frame_word(input_word):
length = len(input_word)
top_bottom_stars = length + 4
spaces_middle = length + 2
star_str(top_bottom_stars)
print '*', spaces_str(spaces_middle), '*'
print '*', input_word, '*'
print '*', spaces_str(spaces_middle), '*'
star_str(top_bottom_stars)
print "Please enter a word:",
input_word = raw_input()
frame_word(input_word)