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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:39:26+00:00 2026-06-03T04:39:26+00:00

What would a very simple while loop statement be that would continue the below

  • 0

What would a very simple while loop statement be that would continue the below program until the user types “exit”?

For example,

while response = (!'exit')
    continue file
else
    break
    print ('Thank you, good bye!')
#I know this is completely wrong, but it's a try!

My file so far:

#!/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']}}
response = raw_input("Please enter search criteria, or type 'exit' to exit the program: ").split()
try:
    print "%s's %s is %s" % (response[0], response[1], friends[response[0]][response[1]])
except KeyError:
    print "Sorry, I don't know about that. Please try again, or type 'exit' to leave the program: "
  • 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-03T04:39:27+00:00Added an answer on June 3, 2026 at 4:39 am

    Your while loop will continue until the condition you’ve set is false. So you want your code to mostly be inside this loop. Once it’s finished, you know the user entered ‘exit’ so you can print the error message.

    #!/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']}}
    
    response = ['']
    error_message = "Sorry, I don't know about that. Please try again, or type 'exit' to leave the program: "
    
    while response[0] != 'exit':
        response = raw_input("Please enter search criteria, or type 'exit' to exit the program: ").split()
        try:
            print "%s's %s is %s" % (response[0], response[1], friends[response[0]][response[1]])
        except KeyError:
            print error_message
        except IndexError:
            print error_message
    
    print ('Thank you, good bye!')
    

    This code is a start to what you want, but it still has some bugs. See if you can restructure it so the error message isn’t printed when the user enters ‘exit’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a very simple template engine that would allow others to
I'm writing a very simple shell scripts that would looked at the log of
I have a very simple Makefile that isn't doing what I expect it would
I've got some long but simple loops in my Delphi program that may loop
I've got a very simple program written in C#, but the loop never exits
I have a very simple question and would be great if someone could save
i would like to generate a very simple report with some images and text
I would like to do a very simple thing but I am quite lost.
I'm writing a very Simple Chat Application and would like to know how to
I need to implement a very simple web-server-like app in Python which would perform

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.