Hello @Sana,
Lines 3, 6-8 look very sketchy.Here is the solution how to do that:
def encode(s):
a,z = ord("a"), ord("z")
return ".".join(
str(ord(c) - a + 1)
if ord(c) in range(a, z + 1) else "999"
for c in s.lower()
)
print(encode("Hello!"))
To be more simple You can try this also:
def encode(strings):
import string
s=''
d={}
for i in string.ascii_lowercase:
d[i]=str(ord(i)-96)
d[' ']='999'
d['!']='999'
s=''
for i in strings.lower():
s+=d.get(i,i)+'.'
return s[0:-1]
print(encode("Hello!"))