As the title suggests, I have a "TypeError: not all arguments converted during string formatting" error in vigenere.py for Pset6.
Here's the code:
import cs50
import sys
if len(sys.argv) == 1 or len(sys.argv) > 2:
print("Usage: python vigenere.py <key>")
exit(1)
key = sys.argv[1]
for i in range(len(key)):
if key[i].isalpha() is not True:
print("Keyword must only contain letters A-Z or a-z")
exit(2)
print("plaintext: ", end="")
plaintext = cs50.get_string()
plaintext_size = len(plaintext)
key_size = len(key)
ciphertext = []
for i in range(plaintext_size):
j = 0
if j >= key_size:
j = 0
if plaintext[i].isalpha():
k = key[j].upper() % 65
c = plaintext[i] + k
if ord(plaintext[i].upper()) + k > ord('Z') or ord(plaintext[i].lower() + k > ord('z')):
c = c - 26
ciphertext.append(chr(c))
j = j + 1
else:
ciphertext[i] = plaintext[i]
print("ciphertext: ", end="")
print("".join(ciphertext))
exit(0)
Any help would be appreciated. Thanks.