我有这段代码
letters = input('Write Text: ')
letters = letters.lower()
numberEn = []
car=["C","A","R"]
carEn=[]
for character in letters:
number = ord(character) - 96
numberEn.append(number)
for number in numberEn:
En = (numberEn)
En = (numberEn(car))
print (En)
我试图做的是改变 嗨到[8,9]确实有效,然后将其改为例如
hi
[8,9]
ca/[c,a]
不起作用我也尝试将其改为字符串
答案 0 :(得分:0)
BASE = ord('a') - 1
def str_to_nums(s):
return [ord(ch) - BASE for ch in s]
def nums_to_str(nums):
return "".join(chr(n + BASE) for n in nums)
print(str_to_nums("hi")) # => [8, 9]
print(nums_to_str([8, 9])) # => "hi"
print(str_to_nums("ca")) # => [3, 1]
print(nums_to_str([3, 1])) # => "ca"