练习内容:判断多个坐标是否在同一条直线上
完整代码和注释如下
def build_wave(strs='example',height=3,width=2,smoothness=3,form='whole'):#设置默认波浪
wave_strs=strs#自定义波浪字符串
strs_len=len(strs)#获取字符串长度
wave_height=strs_len*height#自定义波浪高度 值>0
wave_width=strs_len*width#自定义波浪宽度 值>0
wave_smoothness=smoothness#自定义波浪平滑度 值>0 值越大波浪越平滑
wave_form=form#自定义波浪类型
with open('wave_text.txt','w') as f:
if wave_form=='whole':#整块型
for h in range(wave_height):
if h%2==0:
direction=1#利用奇偶性判断波浪摆动方向
elif h%2==1:
direction=-1
for w in range(wave_width):
for s in range(wave_smoothness):
if direction==1:
f.write(' '*w+wave_strs+'\n')
if direction==-1:
f.write(' &