0
import cs50
import sys
import string


def main():
    # checks if there are two arguments
    if len(sys.argv) != 2:
        print("Incorrect amount of arguments")
        return 1

    # converts argument to key
    key = int(sys.argv[1]) % 26
    # gets text input from user
    plain = cs50.get_string("plaintext: ")

    # displays the first part of ciphertext
    print("ciphertext: ", end='')

    # loops through each character
    for i in range(len(plain)):
        if plain[i].isalpha:
            if plain[i].isupper:
                cipher = ((ord(plain[i]) + key - 65) % 26) + 65
                print(chr(cipher), end='')
            else:
                cipher = ((ord(plain[i]) + key - 97) % 26) + 97
                print(chr(cipher), end='')
        else:
            print(plain[i], end='')

    print("")

    return 0


if __name__ == '__main__':
    main()
0

isalpha and isupper should be called by appending (), like if plain[i].isalpha():

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .