help i have been stuck for the last couple of day but i feel like i am really close just need the push in the right direction. mainly for the this question. how do i go about accessing an the index of the key string in python, and how do i pass that into the function that i have right now. and also what seems to be off to you? how can i improve on this program. thank you very much


also how do i go about debugging python with the cs50 ide


I posted your code into the website PythonTutor (removing the imports of sys and cs50; obviously) and mostly it seemed to be working fine.

The main change to functionality I made was to increment your variable for the key's index, key_index, inside the for loop.

I also added a decipher function based on your cipher function to allow testing for different keys and plaintext values directly in the website (just for testing purposes it will make check50 mess up if you leave it in).


The part I changed:

for i in plaintext:
    if i.isalpha():
        cipher_key = ord(key[key_index % key_len].lower()) - 97
        ciphertext.append(cipher_this(i, cipher_key))
        ## Line below was changed
        ## was cipher_key += 1 to -> key_index += 1 
        key_index += 1 

It's probably also worth noting that "i" here refers to a string char and not an index like it would C.

You must log in to answer this question.

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