Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7014955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:35:22+00:00 2026-05-27T22:35:22+00:00

This is my 1st Python program.I implemented a dictionary as shown below. Here I’m

  • 0

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
>>> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:35:23+00:00Added an answer on May 27, 2026 at 10:35 pm

    The problem is within this line:

    inp=input('Enter M/N:')
    

    You use input instead of raw_input, which you really shouldn’t, as it executes everything the user inputs as Python code. Just use raw_input here and it should be fine.

    However, the rest of your code is also broken and shouldn’t work as you expect it to work. My attempt at fixing it:

    streetno = { "1" : "Sachin Tendulkar",
                 "2" : "Sehawag",
                 "3" : "Dravid",
                 "4" : "Dhoni",
                 "5" : "Kohli"}
    
    # we create a "reversed" dictionary here that maps
    # names to numbers
    streetname = dict((y,x) for x,y in streetno.items())
    
    while True:
        inp = raw_input('Enter M/N:')
        if inp == "M" or inp == "m":
            key = raw_input("Enter the main number:")
            # you don't need .get here, a simple [] is probably what you want
            result = streetno[key]
        else:
            key = raw_input("Enter the street name: ")
            # we need to use our reversed map here!
            result = streetname[key]
    
        # do something with the result (change that to whatever you want
        # to do with it)
        print result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm leaning python and tried this code to test my 1st bit of OOP
What i'm trying to achieve is this: 1st- I want to query a page
I'm in the process of building a site with CodeIgniter. This is the 1st
Lets say you have strings of this format. January 11th, 111 November 1st, 1101
This is my first post here and I wanted to get some input from
I have a list in python. This list has sublist in it. for example:
I am trying to learn python, I was trying write C/C++ code i used
I can't read those special characters I tried like this 1st way # string
I'm starting out in python.. The details I have written in the below.. It
I'm having some trouble with this code. I am trying to write a function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.