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)):

1 Answer 1


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().

  • 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. Apr 2, 2017 at 16:59
  • Answer edited. cs50.get_string = plaintext is not the correction. Apr 2, 2017 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. Apr 2, 2017 at 17:26
  • Or, maybe I didn't get you well? I will appreciate it if you could be more explicit. Thanks. Apr 2, 2017 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! Apr 2, 2017 at 17:47

You must log in to answer this question.

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