Ich muss jedes Zeichen durch das Zeichen nach dem Alphapet durch zwei ersetzen. Zum Beispiel g
bis i
und a
bis c
. Ich bekomme immer diese Fehlermeldung während ich das Programm machte es zu lösenTeilstring nicht gefunden Fehler
substring not found
Hier ist mein Code:
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)
In welcher Zeile heißt es, dass Ihr Fehler stammt? – nbryans
Es sollte sein: y = alphapet.index (x) – Ohumeronen
Nichts in dem Code, den Sie in Ihrer Frage einschließen, wird jemals 'substring not found' drucken. –