I am trying to implement the rot13 algorithm. Obviously not hard but my issue is with strings that have an apostrophe in python I don't know what to do to fix this. I am not sure if the issue is with my program or with the way python runs because I tried running an empty program like so "python3 solve.py ' " and it didn't run but gives me a > in the terminal. I'll also add my code below if anyone sees something else wrong. By empty program, I just call a main that does nothing.
import sys
def main(input):
output = ""
abc = "abcdefghijklmnopqrstuvwxyz"
ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in input:
if ord(i) in range(65,91):
output += ABC[((ABC.find(i) + 13) % 26)]
elif ord(i) in range(97,123):
output += abc[((abc.find(i) + 13) % 26)]
else:
output += i
return output
if __name__ == '__main__':
result = main(sys.argv[1])
print(result)
Single apostrophe serves as a start of quoted, possibly multiline, string and that is the reason for the >
prompt you see. Too send a single apostrophe you can either escape it or quote it with double quotes:
$ python solve.py \'
'
$ python solve.py "'"
'