12/06/2020

Python Explanation (Edabit // Change Every Letter to the Next Letter)

 Hello!

Today is going to be the Python Explanation!

First is the question!

Write a function that changes every letter to the next letter:

  • "a" becomes "b"
  • "b" becomes "c"
  • "d" becomes "e"
  • and so on ...

Examples

move("hello") ➞ "ifmmp"

move("bye") ➞ "czf"

move("welcome") ➞ "xfmdpnf"

Notes

There will be no z's in the tests.

Then it is going to be the solved code.

def move(word):
moved_word = ''
for i in word:
moved_word += chr(ord(i) + 1)
return moved_word

First, we will create a new string.

Then we loop the word.

So we look at the letters of that word.

We will add the off that letter's next letter into the new string.

After we go out of the String, we will return.

It was easy!


Bye!!!




0 件のコメント:

Super Leo 4!

  Leo : Let's do this! Reimu : I'll kill those monsters, so you go! Leo : Yeah! I'll go to the goal!  Leo : Let's go〜! ? Wai...