TypeError: Unable to convert object 'builtin_function_or_method' to str implicitly

I am making a simple mad libs program in python 3 where the user enters nouns and pronouns and the program should print the input from the user.

Here is my code:

print ("Welcome to Mad Libs. Please enter a word to fit in the empty space.")

proper_noun = input("One day _________ (Proper Noun)").lower()
ing_verb = input("Was __________ (Verb + ing) to the").lower()
noun1= input("to the _________ (Noun)").lower()
pronoun1 = input("On the way, _____________ (Pronoun)").lower()
noun2 = input("Saw a ________ (Noun).").lower
pronoun2 = input("This was a surprise so ________ (Pronoun)").lower()
verb2 = input("_________ (verb) quickly.").lower()
#Asks user to complete the mad libs

print ("One day " + proper_noun)
print ("Was " + ing_verb + " to the")
print (noun1 + ". " + "On the way,")
print (pronoun1 + " saw a " + noun2 + ".")
print ("This was a surprise")
print ("So " + pronoun2 + " " + verb2 + " quickly.")

Getting this error code: TypeError: Can't convert 'builtin_function_or_method' object to str implicitly

In this line:

print (pronoun1 + " saw a " + noun2 + ".")

Pretty unexpected for python, so I'm not quite sure what this error means and how to fix it, can someone explain this error code to me, please?

+4
source share
1 answer

The problem is with noun2 variable

noun2 = input("Saw a ________ (Noun).").lower

You assign it the .lower function, not the result of calling it. You must call the function as .lower () -

noun2 = input("Saw a ________ (Noun).").lower()

For future readers

, - TypeError: Can't convert 'builtin_function_or_method' object to str implicitly - +.

, /, .

( OP) , , () ( OP) -

name = name.lower   #It should have been `name.lower()`

() / , . , , , , , , - .

+5

Source: https://habr.com/ru/post/1609066/


All Articles