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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:27:30+00:00 2026-06-08T15:27:30+00:00

I’m sorry if this is a ridiculous question but I’m just learning python and

  • 0

I’m sorry if this is a ridiculous question but I’m just learning python and I can’t figure this out. 🙂

My program is supposed to print the capital of any state that the user inputs. Sometimes it will work ten times in a row, other times it will work three times in a row, and then it will just stop after you type in a state. If I restart it and type in the state that it stopped on it will work just fine….for a random number of times and then it will stop again. What am I doing wrong? Also is my code awful? I had no idea what sort of code to use for this so I just kind of tossed in whatever I could make work.

    x = str(raw_input('Please enter a sate: ' ))
    while x == 'Alabama':
        print 'Montgomery is the capital of', x
        x = str(raw_input('Please enter a state: '))
    while x ==  'Alaska':
        print 'Juneau is the capital of', x
        x = str(raw_input('Please enter a state: '))                  
    while x == 'Arizona':
        print 'Phoenix is the capital of', x
        x = str(raw_input('Please enter a state: ' ))
    while x == 'Arkansas':
        print 'Little Rock is the capital of', x
        x = str(raw_input('Please enter a state: '))'
  • 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-08T15:27:32+00:00Added an answer on June 8, 2026 at 3:27 pm
    1. You mean to use multiple if statements within one big while loop, rather than multiple while loops. In this code, once you’re past one while loop, you never come back to it. This code will work only as long as you are giving it state names in alphabetical order.

    2. Don’t do it this way! There is a much better way to do it using python dictionaries.

      capitals = {"Alabama": "Montgomery", "Alaska": "Juneau", "Arizona": "Phoenix", "Arkansas": "Little Rock"}
      while True:
          x = str(raw_input('Please enter a state: ' ))
          if x in capitals:
              print capitals[x], "is the capital of", x
      

    Otherwise, you’ll end up having 50 pairs of almost identical lines if you want to cover all 50 states.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.