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 7913223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:47:30+00:00 2026-06-03T13:47:30+00:00

As stated in a previous (but different) question, I’m trying to figure out a

  • 0

As stated in a previous (but different) question, I’m trying to figure out a ‘simple’ dictionary/database with Python, which will retrieve a name from a list of ten, with the requested information. i.e. input could be ‘John phone’, where the output is ‘John’s phone number is 0401’ (which I have down pat); but I could also input ‘John Birthday’ or ‘John hobbies’ and the output would correspond.

As I’m a complete noob, I’m not even sure where to start. Several hours of googling and poring over lecture notes have yielded nothing so far.
I’ve got the feeling it’s got something to do with the multiple argument % function but our lecturer really wasn’t clear about how to take it further.
So far, what I have is:

#!/usr/bin/python

friends = {'John': {'phone' : '0401',
                    'birthday' : '31 July',
                    'address' : 'UK',
                    'interests' : ['a', 'b', 'c']},
           'Harry': {'phone' : '0402',
                    'birthday' : '2 August',
                    'address' : 'Hungary',
                    'interests' : ['d', 'e', 'f']}}
name = raw_input ('Please enter search criteria: ')
if name in friends: 
    print "%s's phone number is: %s" % (name, friends[name]['phone'])
else: 
    print 'no data'

I’d also like to use the ‘while’ function so the prog doesn’t close as soon as that information is given, but not sure if this would be appropriate.
Any pointers would be great, even if it’s a ‘try this’ kind of hint, or a link to a relevant website.

  • 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-06-03T13:47:32+00:00Added an answer on June 3, 2026 at 1:47 pm

    Since this is homework, I’ll limit my answer to some hints:

    1. tok = name.split() would split name into a list of words, so 'John address' would become ['John', 'address'].
    2. You can access the individual words as tok[0] and tok[1], and use them to index into friends to get the relevant person and then the relevant field.
    3. I see no problem with wrapping the input/search logic into a while loop so that the user can perform multiple queries. The only thing to figure out is how you’re going to exit that loop.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my previous question Shared vectors in OpenMP it was stated that one can
My question is stated above in the title but I'll write it here again
I've asked a question like this before but this one is different, this is
In a previous question, I asked about various ORM libraries. It turns out Kohana
I'm currently trying to return a single file to the state of a previous
I've got this problem when trying to construct a variable name (which should output
This is semi-related to my previous question . As that previous question states, I
Follow on from a previous question One first screen activity I am clicking a
In a previous Git question , Daniel Benamy was talking about a workflow in
This is a followup to my own previous question and I'm kind of embarassed

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.