-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASCII value
More file actions
30 lines (26 loc) · 1018 Bytes
/
Copy pathASCII value
File metadata and controls
30 lines (26 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def modify_string(s):
modified_chars = set()
modified_string = ""
for i in range(len(s)):
ascii_value = ord(s[i])
if ascii_value % 2 == 0:
new_ascii = ascii_value + (ascii_value % 7)
if chr(new_ascii) not in modified_chars and new_ascii >= 0 and new_ascii <= 127:
modified_string += chr(new_ascii)
modified_chars.add(chr(new_ascii))
else:
modified_string += chr(83)
else:
if i > 0:
new_ascii = ascii_value - (ascii_value % 5)
if chr(new_ascii) not in modified_chars and new_ascii >= 0 and new_ascii <= 127:
modified_string = modified_string[:-1] + chr(new_ascii)
modified_chars.add(chr(new_ascii))
else:
modified_string += chr(83)
else:
modified_string += s[i]
return modified_string
s = "Testing"
modified = modify_string(s)
print(modified)