Я должен заменить каждый символ символом после него двумя в алфавите. Например, g
- i
и a
- c
. Я всегда получаю эту ошибку в то время как я делал программу для ее решенияПодстрока не найдена ошибка
substring not found
Вот мой код:
string="g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
#=========this is the string on the site
alphapet="abcdefghijklmnopqrstuvwxyz"
#this is the alphapet ofcourse
x=""
y=0
z=""
m=0
#that was declaring variables
#the following is a loop which would go through string
for i in string:
#the if statement should check if i was in alphapet string
if i in alphapet:
if i=="y":
string.replace(i,"a")
elif i=="z":
string.replace(i,"b")
#the previous two conditions were special cases
else:
#the x will equal the first character as m =0 which is"g"
x=string[m]
#the y should equal the index of the character in alphapet this is were the error comes
y=alphapet.index(x)
#the z should equal the letter that comes after it by 2 in alphapet
z=alphapet[y+2]
#the following line should replace it
string.replace(i,z)
m+=1
print(string)
В какой строке говорится, что ваша ошибка возникает? – nbryans
Он должен быть: y = alphapet.index (x) – Ohumeronen
Ничто в коде, который вы включили в свой вопрос, никогда не будет напечатано 'substring not found'. –