Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next Letter in alphabet

Tags:

python

string

I am stuck on how to make Z turn into A on the cs circles problem Next Letter

x =input()

x=x.upper()

x=chr(ord(x) + 1)

print(x)

how do i get z to turn into A?

like image 798
Harpoonfever Avatar asked Mar 12 '19 06:03

Harpoonfever


People also ask

What comes next in alphabet series?

With reference to English alphabet, the first alphabet and the last one are clubbed together. Similarly, the second and second from the last are placed together. Following this pattern, the next set of alphabets would be DW.

What comes after alphabet A to Z?

Notes. Five of the letters in the English Alphabet are vowels: A, E, I, O, U. The remaining 21 letters are consonants: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, X, Z, and usually W and Y.

What is the next letter Ottffss?

According to this explanation, OTTFFSS riddle answer and answer to What are the next three letters in this combination question is ENT as they represent numbers Eight, Nine and Ten.


1 Answers

Using chr and ord:

def next_alpha(s):
    return chr((ord(s.upper())+1 - 65) % 26 + 65)

for s in 'abcdefghijklmnopqrstuvwxyz':
    print('%s --> %s' % (s, next_alpha(s)))

a --> B
b --> C
...
y --> Z
z --> A
like image 84
Chris Avatar answered Oct 05 '22 10:10

Chris