Python Forum
ValueError: substring not found
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: substring not found
#1
Hello,

I encountered this issue when self-learning Python. Could anyone give me a full explanation what is happening here? Any help would be greatly appreciated. Thank you!

def shift(char, key):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    updated_alphabet = ""
    if int(key) > 0:
        for i in range(len(alphabet)):
            updated_alphabet += alphabet[(int(key) + i) % 26]
    char_index = alphabet.index(char.lower())
    new_char = updated_alphabet[char_index]
    return new_char
def main():
    message = "Please help me with this."
    new_mess = ""
    for char in message:
        new_mess += shift(char, 1)
    return new_mess
main()
Reply


Messages In This Thread
ValueError: substring not found - by hoangthai10788 - Sep-23-2019, 03:42 PM
RE: ValueError: substring not found - by ichabod801 - Sep-23-2019, 05:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extract substring from a string before a word !! evilcode1 3 578 Nov-08-2023, 12:18 AM
Last Post: evilcode1
  [SOLVED] [regex] Why isn't possible substring ignored? Winfried 4 1,103 Apr-08-2023, 06:36 PM
Last Post: Winfried
  ValueError: substring not found nby2001 4 8,018 Aug-08-2022, 11:16 AM
Last Post: rob101
  Match substring using regex Pavel_47 6 1,482 Jul-18-2022, 07:46 AM
Last Post: Pavel_47
  ValueError: Found input variables with inconsistent numbers of samples saoko 0 2,498 Jun-16-2022, 06:59 PM
Last Post: saoko
  Substring Counting shelbyahn 4 6,174 Jan-13-2022, 10:08 AM
Last Post: krisputas
  Python Substring muzikman 4 2,354 Dec-01-2020, 03:07 PM
Last Post: deanhystad
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 2,577 Nov-23-2020, 05:15 PM
Last Post: cananb
  Removing items from list if containing a substring pythonnewbie138 2 2,235 Aug-27-2020, 10:20 PM
Last Post: pythonnewbie138
  Substring and If then Condition to create column Chandan 2 2,369 Jan-23-2020, 08:40 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020