From 1bb8799f64286baec223cddf087afd94db4f2f87 Mon Sep 17 00:00:00 2001 From: Angus B <38348730+LetsCode-Angus@users.noreply.github.com> Date: Sat, 2 Nov 2019 11:19:55 +1100 Subject: [PATCH] Small revisions Fixed spelling mistakes and style issues. Improved efficiency by removing repeated calls to `ord()`. Overall pretty call project bro. --- caesar-shift.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/caesar-shift.py b/caesar-shift.py index 32ff057..94b9a74 100644 --- a/caesar-shift.py +++ b/caesar-shift.py @@ -9,21 +9,23 @@ fileDirectory=str(sys.argv[2]) shiftNum=int(sys.argv[1]) # var shiftNum is the number of shifts -def doShift(value,shift): +def doShift(value, shift): done = value + shift % 90 if done > 90: - done-=26 + done -= 26 return done -with open(fileDirectory,"r") as file1: # opens the file - while True: - charecter = file1.read(1) - if not charecter: - break - charecter=charecter.upper() +if __name__ == "__main__": + + with open(fileDirectory,"r") as file: # opens the file + while True: + character = file.read(1) + if not character: + break + unicode = ord(character.upper()) - if ord(charecter) <= 90 and ord(charecter) >= 65: - result=chr(doShift(ord(charecter),shiftNum)) - else: - result = charecter - sys.stdout.write(result) + if unicode <= 90 and unicode >= 65: + result = chr(doShift(unicode, shiftNum)) + else: + result = chr(unicode) # Converts unicode ID back to char + sys.stdout.write(result)