name '' is not defined [duplicated]

0

It's a story where you enter names but you're not recognizing them quit NameError: name '' is not defined

Apparently it does not recognize the string.

girldescription = " " 
boydescription = " " 
walkdescription = " " 
girlname = " "
boyname = " "
animal = " "
gift = " " 
answer = " "


girlname = input("Enter a girl's name: ")
boyname = input("Enter a boy's name: " )
animal = input("Name a type of animal: " )
gift = input("Name something you find in the bathroom: ")
girldescription = input("Enter a description of a flower: ")
boydescription = input("Enter a description of a car: ")
walkdescription = input("Enter a description of how you might dance: " )
answer = input("What would you say to someone who gave you a cow: ")



print ("Once upon a time,")
print("there was a girl named " + girlname.capitalize() + ".")
print("One day, " + girlname.capitalize() + " was walking " + walkdescription.lower() + " down the street.")
print("Then she met a " + boydescription.lower() + " boy named " + boyname.capitalize() + ".")
print("He said, 'You are really " + girldescription.lower() + "!'")
print("She said '" + answer.capitalize() + ", " + boyname.capitalize() + ".'")
print("Then they both rode away on a " + animal.lower() + " and lived happily ever after.")
    
asked by FerJPi 03.11.2017 в 17:19
source

1 answer

0

What happens is that input captures the data but before interprets it, that is, it is trying something like

nombre = CARLOS 

And I return the error to you

name "CARLOS" is not defined

So for your code to work you would have to enter the values in the console, if for example you run your code and instead of typing CARLOS you type "CARLOS" , it will not give you an error.

For this reason it would be best to use raw_input in no input , here you can check more information

example:

Enter a girl's name: "Andrea"

or if you do not change to raw_input you can enter it normally, another thing you do not need to define the variables as empty at the beginning.

girlname = raw_input("Enter a girl's name: ")
boyname = raw_input("Enter a boy's name: " )
animal = raw_input("Name a type of animal: " )
gift = raw_input("Name something you find in the bathroom: ")
girldescription = raw_input("Enter a description of a flower: ")
boydescription = raw_input("Enter a description of a car: ")
walkdescription = raw_input("Enter a description of how you might dance: " )
answer = raw_input("What would you say to someone who gave you a cow: ")



print ("Once upon a time,")
print("there was a girl named " + girlname.capitalize() + ".")
print("One day, " + girlname.capitalize() + " was walking " + walkdescription.lower() + " down the street.")
print("Then she met a " + boydescription.lower() + " boy named " + boyname.capitalize() + ".")
print("He said, 'You are really " + girldescription.lower() + "!'")
print("She said '" + answer.capitalize() + ", " + boyname.capitalize() + ".'")

Greetings

    
answered by 03.11.2017 в 17:36