![](/img/trans.png)
[英]I am generating images that will be continuously into a folder as an output. My goal is to change the output location to another computer
[英]I am wrapping a string for a given width, but my code is not generating expected output
我怎样才能找到错误? 这是我的代码:
i=0
def wrap(string, max_width): # function for providing string and max_width
for i in range(0,len(string)):
print(string[i:i+max_width])
i=i+max_width # incrementing 'i' as per the max_width added by the user.
上面的代码o/p:
input : 'vivek'
output: 'vi'
'iv'
've'
'ek'
'k'
正确的 O/P:
'vi'
've'
'k'
您不能像这样增加在for
循环中使用的变量,因为它们会在下一次迭代中被覆盖。 任何一个:
range
增加max_width
: range(0,len(string),max_width)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.