0
def newname():
    info= {}
    info["fname"] = input("What is this contacts first name: ")
    info["lname"] = input("What is this contacts last name: ")
    info["address"] = input("What is this contacts address: ")
    info["city"] = input("What is this contacts city: ")
    info["state"] = input("What is this contacts state: ")
    info["zip"] = input("What is this contacts zip: ")
    info["number"] = input("What is this contacts number: ")
    addressbook.append(info)

I am trying to create an address book and for the adding a new person, when running my dictionary I get this error message File "line 3, in newname info["fname"] = input("What is this contacts first name: ") File "", line 1, in NameError: name 'Rob' is not defined. Just wondering what I'm missing here. Thanks for the help.

  • You really need to tag your questions with the relevant language. I'm going to guess Python 2.x, in which case the ``input()`` function takes an arbitrary Python expression - you'd have to enclose the input in quote marks to make it a valid string. ``raw_input()`` is what you actually want to use here, it doesn't try to interpret what you typed. – jasonharper Feb 24 '17 at 04:33
  • Apologies about not including the language. It's python 3.6. And thanks for the assistance. – Robert Nelson Feb 24 '17 at 14:51
  • It CAN'T be Python 3.6 - there, ``input()`` is exactly what you want, doing what ``raw_input()`` did in 2.x and earlier. – jasonharper Feb 24 '17 at 15:23
  • I am debugging in Visual Studio code, and using IDLE to run my code for class. The IDLE version is for sure 3.6. When I run this program within the compiler(IDLE) no matter how I implement input it still does not run anything. However in Visual Code it works just fine with the raw_input implementation. I am very confused. – Robert Nelson Feb 24 '17 at 17:18

0 Answers0