austin
New Coder
I am trying to write a code that will transform a string to the given pattern. Let me give you more examples.
If we write "miracle", the letters will be upper case (MIRACLE) and after that we will have numbers between the letters -- "M1I2R3A4C5L6E" (There won't be a number after the last letter.)
If we write "bASebALL", again all letters will be upper case, there will be numbers in ascending order between them. -- "B1A2S3E4B5A6L7L"
To solve this, I tried to find a code that will insert something simple in between letters first. Like dashes. (SOURCE: https://stackoverflow.com/questions/29382285/python-making-a-function-that-would-add-between-letters)
>>> def f(s):
m = s[0]
for i in s[1:]:
m += '-' + i
return m
>>> f("James")
But, I couldn't change the code into a code which inserts ascending numbers between letters.
Also I have this piece of code I wrote for upper casing the word.
mystr = 'james'
mystr_up = mystr.upper()
mystr_up
It successfully prints "JAMES". But I don't know how to use this code to create a while or for loop.
Also the code must start like this:
def strPattern(mystr):
and at the end we have to use "return"
If we write "miracle", the letters will be upper case (MIRACLE) and after that we will have numbers between the letters -- "M1I2R3A4C5L6E" (There won't be a number after the last letter.)
If we write "bASebALL", again all letters will be upper case, there will be numbers in ascending order between them. -- "B1A2S3E4B5A6L7L"
To solve this, I tried to find a code that will insert something simple in between letters first. Like dashes. (SOURCE: https://stackoverflow.com/questions/29382285/python-making-a-function-that-would-add-between-letters)
>>> def f(s):
m = s[0]
for i in s[1:]:
m += '-' + i
return m
>>> f("James")
But, I couldn't change the code into a code which inserts ascending numbers between letters.
Also I have this piece of code I wrote for upper casing the word.
mystr = 'james'
mystr_up = mystr.upper()
mystr_up
It successfully prints "JAMES". But I don't know how to use this code to create a while or for loop.
Also the code must start like this:
def strPattern(mystr):
and at the end we have to use "return"