File "caesar.py", line 28, in for i in range (len (plaintext)): TypeError: object of type 'function' has no len()

This is the relevant part of the code, I guess. If need be I can post the whole code.Thanks

plaintext = cs50.get_string

print ("Ciphertext:")

i = 0

for i in range (len (plaintext)):


First, especially with python because spaces/indents are crucial, but in general, you need to format your code properly. To that, edit the question, select the code, press the {} in the format bar, and it will be done for you. That same trick works on an initial post.

An important lesson here: cs50.get_string is the function. cs50.get_string() executes the function. You have set plaintext to the function, thus the complaint about len. You need to set plaintext to the result of the function: plaintext = cs50.get_string().

| improve this answer | |
  • Ok, Dino. I did cs50.get_string = plaintext and still got the same error. will just do as you request and rephrase th question. Thanks. – doublestanding Apr 2 '17 at 16:59
  • Answer edited. cs50.get_string = plaintext is not the correction. – DinoCoderSaurus Apr 2 '17 at 17:22
  • Sure, I had to present it i the mode it was when I asked the question initially. When cs50.get_string = plaintext didn't work. I decided to represent in the initial code. – doublestanding Apr 2 '17 at 17:26
  • Or, maybe I didn't get you well? I will appreciate it if you could be more explicit. Thanks. – doublestanding Apr 2 '17 at 17:28
  • Problem, solve. I was foolish enough not add () after the get_string function!!!. That caused me a lot of headache. Other things wrong with the code is being taken care of. Thanks! – doublestanding Apr 2 '17 at 17:47

You must log in to answer this question.

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