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?
snakecharmerb
39.2k10 gold badges77 silver badges125 bronze badges
asked Mar 12, 2019 at 6:04
5
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
answered Mar 12, 2019 at 6:16
ChrisChris
27.7k3 gold badges25 silver badges47 bronze badges
Here is the solution to find the next alphabets of multiple alphabets.
Example:
input - abc
output - bcd
user_input = input["Enter your word: "]
lst = list[''.join[user_input.lower[]]]
lst1= []
str1='' for i in range[len[lst]]:
x = ord[lst[i]] #ord[] is used to convert char to ascii value
x=x+1
if x==123:
x=97
y= chr[x]
lst1.append[y]
str1 =''.join[lst1]
else:
y= chr[x] #chr[] is used to convert ascii to char value
lst1.append[y]
str1 =''.join[lst1]
print[str1]
answered Jun 13, 2021 at 17:17
Try below code to solve Next Letter
Question.
charac = input[]
if charac == "Z": # If Z encountered change to A
print[chr[ord[charac]-25]]
else:
change = ord[charac] + 1
print[chr[change]]
answered Mar 12, 2019 at 6:09
skaul05skaul05
2,0092 gold badges15 silver badges24 bronze badges
0
You can subtract 25 from the ord
value of 'Z' or 'z':
x = input['Enter Alphabet: ']
print[chr[ord[x]-25]]
Output:
Enter Alphabet: z
a
answered Mar 12, 2019 at 6:09
heena bawaheena bawa
8086 silver badges5 bronze badges
1
Use the below code, this code allows users to type in multiple letters:
import string
letters = string.ascii_letters
x = input[]
x = list[x.lower[]]
for i,v in enumerate[x]:
x[i] = letters[letters.index[v] + 1]
print[''.join[x].upper[]]
Example output:
azd
BAE
If you don't need them to type in multiple letters, use:
import string
letters = string.ascii_letters
x = input[]
x = x.lower[]
x = letters[letters.index[x] + 1]
print[x.upper[]]
Example output:
z
A
answered Mar 12, 2019 at 6:09
U12-ForwardU12-Forward
66.2k13 gold badges76 silver badges96 bronze badges
0
try this:
x = input[]
x = x.upper[]
order = ord[x]
if order ==90:
order = 64
x=chr[order + 1]
print[x]
answered Mar 12, 2019 at 6:08
Amit NanawareAmit Nanaware
3,0571 gold badge5 silver badges19 bronze badges
0
to increment the alphabet in lower case in clockwise
a = input["ENTER THE ALPHABET:"]
inc=int[input["ENTER INCREMENT VALUE:"]]
x = ord[a]
x=x+inc
if x>=123:
x=x-122
x=96+x
print[chr[x]]
else:
print[chr[x]]
PM 77-1
12.5k20 gold badges65 silver badges108 bronze badges
answered Jan 7 at 14:01
2