[英]Program which takes an input of the Alphabet and outputs the character which is next in the Alphabet
[英]Write a program that takes a character as input (string length 1) the output is the next character in the alphabet. If input is 'Z', output is 'A'
編寫一個程序,輸入一個字符(長度為 1 的字符串),你應該假設它是一個大寫字符; 輸出應該是字母表中的下一個字符。
如果輸入是'Z'
,你的輸出應該是'A'
。
這是我到目前為止所做的,但是當我輸入Z
時我沒有得到A
。 我得到[
。
請幫忙,我做錯了什么?
input = (input()).upper()
for character in input:
number = ord(character) + 1
number1 = chr(number)
if ord('z'):
new_number = ord(character) - 25
number2 = chr(new_number)
print(number1)
一種方法可能是通過
match<\/code>語句:
match (letter):
case 'A':
print('B')
case 'B':
print('C')
我已經想通了!! 感謝大家用另一種方法伸出援手! 我永遠感激不盡。
input = (input()).upper()
encrypted = ""
for character in input:
if character == "":
encrypted += ""
elif ord(character) + 1 > ord("Z"):
encrypted += chr(ord(character) + 1 - 26)
else:
encrypted += chr(ord(character) + 1)
print(encrypted)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.