你需要的是一种方法来一遍又一遍地让每个字符您的manipulateinput
串的,所以你不要跑出来的字符。
mystring = 'string'
assert 2 * mystring == 'stringstring'
但有多少次重复:
您可以因此被重复多次的字符串倍增,因为你需要做到这一点?那么,你得到使用len
一个字符串的长度:
assert len(mystring) == 6
因此,要确保您的字符串是至少只要另一个字符串,你可以这样做:
import math.ceil # the ceiling function
timestorepeat = ceil(len(originalinput)/len(manipulateinput))
newmanipulateinput = timestorepeat * manipulateinput
另一种方式不要将它用INT除法,或//
:
timestorepeat = len(originalinput)//len(manipulateinput) + 1
newmanipulateinput = timestorepeat * manipulateinput
现在你可以使用一个for循环不会耗尽字符:
result = '' # start your result with an empty string
for character in newmanipulateinput:
# test to see if you've reached the target length yet
if len(result) == len(originalinput):
break
# update your result with the next character
result += character
# note you can concatenate strings in python with a + operator
print(result)
问题再次出现了什么?... – 2015-01-26 18:18:21
这是一个家庭作业问题吗?可以的,如果是的话,但是帮助建议你这样说在你的问题前面,它可以让人们更有效地帮助你,另外:试着至少包含一些你试过的代码,以便对它进行破解 – 2015-01-26 18:18:29
这是我给出的问题:“keywor d重复 足够的时间以匹配明文消息的长度。“。我可以将其余的程序添加到我已经拥有的代码段中,这只是我完成了一些作业:) – KBHO 2015-01-26 18:22:24