This is my 1st Python program.I implemented a dictionary as shown below. Here I'm trying to retrieve values*(either key or value)* depending upon the user input.
For eg: If user enters "1" then I need to retrieve "Sachin Tendulkar " from the dictioanry. If user enter "Sachin Tendulkar" then I need to retrieve "1" from dictioanry.
streetno={"1":"Sachin Tendulkar","2":"Sehawag","3":"Dravid","4":"Dhoni","5":"Kohli"}
while True:
inp=input('Enter M/N:')
if inp=="M" or inp=="m":
key=raw_input( "Enter the main number :")
result=streetno.get(key)
else:
key=raw_inp("Enter the street name : ")
result=streetno.get(key)
I think there's nothing wrong with the logic. But i'm not able to execute it. I'm getting below shown error.
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Enter M/N:m
Traceback (most recent call last):
File "C:\Users\kiran\Desktop\Cricketpur.py", line 3, in <module>
inp=input('Enter M/N:')
File "<string>", line 1, in <module>
NameError: name 'm' is not defined
>>>
input(which you really should, as it opens a large security hole),raw_inputandraw_inp, the latter of which does not exist. Also, are you aware that indentation is part of the logic of a Python program?