+ 6
Why it is a Value error :substring not found?
Here is a new one https://code.sololearn.com/cmlkxWOmlHyG/?ref=app
13 Answers
+ 2
because " " (space) is not in the list!
change for loop section of your code to the following:
for ltr in msg:
if ltr in alphnew:
place=alph.index(ltr)
message += alphnew[place]
else:
message+= ltr
+ 7
I applied it.
+ 7
When I write "sololearn" the result is correct, if I write "Vegetable pizza", ValueError is appeared.
+ 7
Shadoff ,now it works fine. THANKS to all of You. ☺️👍
+ 7
visph ,OK Thank You very much.
+ 6
+ 5
Egor Tonchev(EGO) ,
i saw your last version, but there is still an issue with it. you have added a space to the alphabet variable at index 0, then this variable will be reversed. that is ok for all letters but not for spaces. a space has to be "translated" to space again.
so the space in regular alphabet is at index 0, and in reversed in index 26. but the space in both strings has to be in the same index. to get rid of this issue you can do:
...
alp= " abcdefghijklmnopqrstuvwxyz" # ok
alpn = ' ' + alp[::-1] # <<<<<<
...
then it should work.
happy coding!
+ 2
error comes when index() did not found the argument string in thd target string: 'alphabet' not contains the char provided...
you must:
• test if ltr is a letter
• make the letter uppercase
• check the 'alphabet value': at least E is not inside (but you have twice I)
+ 2
Ну работает же!
по задумке это должно быть закодированное письмо с заменой букв на буквы по тому же номеру в алфавите только задом на перед?
+ 1
the problem is here:
message+=z[plc]
+ 1
Egor Tonchev(EGO) your actual code linked in question is empty ^^
+ 1
your code works fine if you only provide lowercase letter as input...
you still have to test if each char is a letter (and just append it to result if not), turn it to lowercase if uppercase (and maybe turn the result char to uppercase)...
+ 1
"""
Egor Tonchev(EGO) I said you from start ^^
however, not all works fine in your actual code: 'a' is converted to a space... wich I think is not expected, 'b' to 'z', 'c' to 'y'...
I guess you rather want 'a' to 'z', 'b' to 'y', 'c' to 'x'... and maybe keep lower/upper case:
"""
msg = input()
alph = "abcdefghijklmnopqrstuvwxyz"
alphnew = alph[::-1]
message = ""
for ltr in msg:
if ltr.isalpha():
up = ltr.upper()==ltr
place = alph.index(ltr.lower())
ltr = alphnew[place]
if up: ltr = ltr.upper()
message += ltr
print(message)