Getting string index out of range? python 3

后端 未结 2 1743
灰色年华
灰色年华 2021-01-25 06:59

My program is supposed to take an input in form of a string and split into to strings, one with all the lower case letters, underscores and dots. The other one with all the uppe

2条回答
  •  情书的邮戳
    2021-01-25 07:31

    as @willemVanOnsem pointed out, you are recursively calling this on the string minus the first char. Eventually, you are calling it on an empty string, which is why you get an index error. check that "letters" is not empty before doing anything else.

    as a side note, I don't think your recursive call is going to do what you expect.

    can you use a while loop? you mention not using a for loop? or do you have to use recursion?

提交回复
热议问题