问题描述
我正在制作一个 twitch 机器人,并且想要一个金字塔命令,它会在聊天中发送一个横向金字塔,看起来像这样 => https://i.imgur.com/pzKMH2i.png
目前它在一行中全部打印,但是它打印的数量正确,但它应该是横向而不是直立的。
将 pyramid_width 更改为“a”可以修复它,但是它需要发送聊天中指定的单词。 https://i.imgur.com/HP2eRoQ.png
我不确定如何实际解决此问题,因此将不胜感激
def send_pyramid(width,text,channel):
text = str(text) + " " if not str(text).endswith(" ") else str(text)
while text.find(' ') != -1:
text.replace(' ',' ')
for i in range(0,width + 1):
sendcommand("/me " + i * text,channel)
width -= 1
while width != 0:
sendcommand("/me " + width * text,channel)
width -= 1
def get_first_nbr_from_str(input_str):
'''
:param input_str: strings that contains digit and words
:return: the number extracted from the input_str
demo:
'ab324.23.123xyz': 324.23
'.5abc44': 0.5
'''
if not input_str and not isinstance(input_str,str):
return 0
out_number = ''
for ele in input_str:
if (ele == '.' and '.' not in out_number) or ele.isdigit():
out_number += ele
elif out_number:
break
return float(out_number)
def clearup(s,chars):
return re.sub('[%s]' % chars,'',s).lower()
if "++test" in chat:
echo = chat.replace("++test","")
echo = str(echo)
pyramid_width = (get_first_nbr_from_str(echo)) # finds the number
pyramid_width = int(pyramid_width)
pyramid_text = clearup(echo,string.punctuation+string.digits) # replaces number
print(pyramid_text)
for i in range(0,pyramid_width + 1):
print(i * pyramid_text)
pyramid_width -= 1
while pyramid_width != 0:
print(pyramid_width * pyramid_text)
pyramid_width -= 1
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)