In my sentence i want :
- replace every # by *
- skip every ?
- if the ascii value of a char is pair so i am transforming into LowerCase + Shift Value ( input user)
- if the ascii value of a char is impair so i am transforming into UpperCase + Shift Value ( input user) Its tell me
line 19, in replace new = ord(lower(c)) + (shift % 26) TypeError: ord() expected string of length 1, but NoneType found
def lower(c):
if 'A' <= c <= 'Z':
c = chr(ord(c) + (ord('a') - ord('A')))
def upper(c):
if 'a' <= 'c' <= 'z':
c = chr(ord(c) - (ord('a') - ord('A')))
def replace(text):
new_text = ''
for c in text:
if c == '#':
new_text += '*'
elif c == '?':
continue
elif ord(c) % 2 == 0:
new = ord(lower(c)) + (shift % 26)
if new > ord('z'):
new = (ord('a') + (new - ord('z')))
new_text += chr(new)
elif ord(c) % 2 != 0:
new = ord(upper(c)) + (shift % 26)
if new_text > 'Z':
new_text = chr('Z' + (new_text - 'Z'))
new_text += chr(new)
return new_text
sentence = (input("Please enter a sentence to encrypt:\n"))
shift = int(input("Please enter the size of the shift:\n"))
sentence = replace(sentence)