My code (now):
import cs50
import sys
if len(sys.argv) != 2:
print("usage: python caesar.py key")
exit(1)
else:
key = sys.argv[1]
c = int(key) % 26
cphtxt = 0
if c < 1:
print("bigger key than 0 please")
exit(2)
print("plaintext:")
plaintext = cs50.get_string()
print("ciphertext:")
for i in range(len(plaintext)):
if(plaintext[i].isalpha):
if(plaintext[i].isupper):
cphtxt = ((ord(plaintext[i]) - 65 + c) % 26) + 65
print(chr(cphtxt), end = "")
else:
cphtxt = ((ord(plaintext[i]) - 97 + c) % 26) + 97
print(chr(cphtxt), end = "")
else:
print(plaintext[i])
exit(0)
The error is gone, but now a couple of issues.
The first one is the output is all capital. If I type in "Hello", out comes "LOVVY" When "Lovvy" should be coming out.
The second one is non alpha characters come out shifted. If I type in ",", out comes "J".
How do I fix this? Thanks,
A (confused) ian