Zen Mournster Zen Mournster - 7 days ago 6
Python Question

What is wrong with my dictionary?

I am learning to create dictionaries with Python and I created the one below to take the information of a detainee at the booking center of a local police station. The information is user inputed:

local_police = {'Name' : " ",'Phone number' : '','Address' : " ", 'Registered' : ' ','posession' : []} """a dictionary for the suspects details"""

local_police['Name']=raw_input("Enter suspects name:")
local_police['Phone Number']=input("Enter phone number:")
local_police['Address']=raw_input("Enter Address:")
local_police['Registered']=raw_input("Has suspect been registered? Y/N:")
local_police['posession']=raw_input("items in suspect's backpack (seperate each item with a comma):")

print local_police


I notice that I can not successfully input any value into the 'Phone Number' key in the dictionary. Can someone please explain why?

EDIT: I would clarify the post further by adding the following:

My expected output is to look as follows:

Enter suspects name:thief dude
>>> local_police['Address']=raw_input("Enter Address:")
Enter Address:theif house
>>> local_police['Registered']=raw_input("Has suspect been registered? Y/N:")
Has suspect been registered? Y/N:Y
>>> local_police['posession']=raw_input("items in suspect's backpack (seperate each item with a comma):")
items in suspect's backpack (seperate each item with a comma):gun,knife,puppy
>>> local_police['Phone Number']=raw_input("Enter phone number:")
Enter phone number:111111
>>> print local_police
{'Phone number': '', 'Name': 'thief dude', 'Registered': 'Y', 'Phone Number': '111111', 'posession': 'gun,knife,puppy', 'Address': 'theif house'}










You would notice that upon printing, two keys were printed for Phone number. One with the value of 111111(value entered by the user)and the other empty:

{'Phone number': '', 'Name': 'thief dude', 'Registered': 'Y', 'Phone Number': '111111', 'posession': 'gun,knife,puppy', 'Address': 'theif house'}

Answer

I think that your problem is Phone number is written with lowercase n in the dictionary but when you ask for input it is written Phone Number with uppercase n.

Comments