#
# Happy Valentine ;)
# 報われないおまいらのためにハートを授けよう。
#
import sys
import math
# 引数チェック
# - 5以上
# - 奇数
if len(sys.argv) <= 1:
print("引数入れてね")
exit()
num = int(sys.argv[1])
if num < 5 or num % 2 == 0:
print("引数は5以上の奇数で入れてね")
exit()
# 上部
top = ""
top_num = math.floor(num / 2) - 1
for i in range(0, top_num):
top = " "
for j in range(0, top_num - i - 1):
top += " "
if i == 0:
top += "/ ̄\/ ̄\"
else:
top += "/"
for j in range(0, 2 * i + 4):
top += " "
top += "\"
print(top)
# 中部
mid_space = ""
mid_num = math.floor(num / 2) - 1
for i in range(0, mid_num):
mid_space += " "
print("|" + mid_space + " LOVE " + mid_space + "|")
# 下部
btm = ""
btm_num = math.floor(num / 2)
for i in range(btm_num, -1, -1):
btm = " "
for j in range(0, btm_num - i):
btm += " "
btm += "\"
for j in range(0, i * 2):
btm += " "
btm += "/"
print(btm)
$ python ValentineHeart.py 5
/ ̄\/ ̄\
| LOVE |
\ /
\ /
\/
$ python ValentineHeart.py 7
/ ̄\/ ̄\
/ \
| LOVE |
\ /
\ /
\ /
\/
$ python ValentineHeart.py 9
/ ̄\/ ̄\
/ \
/ \
| LOVE |
\ /
\ /
\ /
\ /
\/
ちょっといびつだけど、許して(はぁと
追伸:
これを使って、ソースコードコメントの有用性について語ったブログも書いたので、参考までにどぞ。
http://hanakayui0628.hatenadiary.jp/entry/2018/02/16/125855