简体   繁体   中英

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'

Write a program that takes a character as input (a string of length 1), which you should assume is an upper-case character; the output should be the next character in the alphabet.

If the input is 'Z' , your output should be 'A' .

Here's what i've done so far but I'm not getting A when I input Z . I'm getting [ .

Please help, what am I doing wrong?

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)

A way of doing this may be via a match<\/code> statement:

match (letter):
    case 'A':
        print('B')
    case 'B':
        print('C')

I have figured it out!! Thanks to everyone for reaching out with an alternative method! I'm ever grateful.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM