因此,我尝试使用字符串将字符串中的字符替换为字母的下一个字母。我已经转换了输入,但是我不知道该怎么办? 这是我的代码:
alphabet =['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
wordlist = []
inputword = input("Please enter a string")
wordlist = list(inputword)
for i in range(len(inputword)):
print (wordlist)
我正在尝试获取它,以便如果我输入“ Hello World”,它将返回“ Ifmmp xpsme”
不必返回确切的大小写(大写字母可以小写返回
答案 0 :(得分:0)
如果我理解正确,则希望将用户提供的字符替换为字母的下一个字符。
假设mysqli_select_db($conn, $database_name);
应该变成z
,请使用以下命令:
a
alphabet =['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
wordlist = []
inputword = input("Please enter a string:")
wordlist = list(inputword)
if wordlist[0] == 'z':
#print('Sorry, I do not know what to do for this case')
idx = 0
new_word = alphabet[idx]
print(new_word)
else:
idx = alphabet.index(wordlist[0])
new_word = alphabet[idx +1]
print(new_word)
示例:
def next_letter(st):
index = 0
new_word = ""
alphapet = "abcdefghijklmnopqrstuvwxyzacd"
for i in st.lower():
if i.islower(): #check if i s letter
index = alphapet.index(i) + 1 #get the index of the following letter
new_word += alphapet[index]
else: #if not letter
new_word += i
return new_word
USER_INPUT = input('enter string:')
next_letter(USER_INPUT)