python - 连续打印一定次数的东西
问题描述
我正在制作一个 twitch 机器人,并希望有一个金字塔命令,该命令将在聊天中发送一个横向金字塔,如下所示 => https://i.imgur.com/pzKMH2i.png
目前它在一行中打印所有内容,但打印数量正确,但它应该是横向而不是直立的。
将 pyramid_width 更改为“a”可以修复它,但是它需要发送聊天中指定的单词。https://i.imgur.com/HP2eRoQ.png
我不确定如何实际解决此问题,因此将不胜感激<3
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
解决方案
推荐阅读
- python - 多对多关系上的SqlAlchemy外键错误
- python - Discord Bot - “属性错误:'NoneType' 对象没有属性'strip。'
- ios - 当用户对我的应用进行评分或点击“不是现在”以显示应用商店审核请求弹出窗口时,我能否得到回复?
- c++ - 带有“extern”和“inline”说明符的变量
- c# - 无法解析压缩、加密、解密、解压流实现
- sql-server - Sp_Colums, Sp_procedures 消耗资源
- c - C整数溢出解释
- javascript - 在 Spotify API 授权期间获取 HTTP 415 Unsupported Media Type
- bash - 参数扩展默认 ":=" vs "=" vs ":-" vs "-"
- swift - iOS 13 SwiftUI 中的 UIToolbar?