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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:36:35+00:00 2026-06-15T07:36:35+00:00

I want to write an interface using a while loop and raw_input. My code

  • 0

I want to write an interface using a while loop and raw_input.

My code looks like this:

while True:
    n = raw_input("'p' = pause, 'u' = unpause, 'p' = play 's' = stop, 'q' = quit)
    if n.strip() == 'p':
        mp3.pause()
    if n.strip() == 'u':
        mp3.unpause()
    if n.strip() == 'p':
        mp3.play()
    if n.strip() == 's':
        mp3.stop()
    if n.strip() == 'q':
        break

But I want it to break if I input anything that isn’t specified in the raw_input.

    if not raw_input:
        break

Returns and IndentationError: unindent does not match any outer indentation level.

        if not raw_input:
            break

Does not return any error but doesn’t work as I want it to. As far as I know, it does nothing at all.

Also, if there’s a cleaner way to write my loop, I love to hear it.

  • 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-15T07:36:36+00:00Added an answer on June 15, 2026 at 7:36 am

    You are getting an indent error because you do not have a closing double quote.

    n = raw_input("'p' = pause, 'u' = unpause, 'p' = play 's' = stop, 'q' = quit")
    

    If you want to have the while look break if there is any other value then put all of your conditions into elif statements, and an all includisve else at the end. Also I just put lower and strip onto the end of the raw_input statement.

    while True:
        n = raw_input("'p' = pause, 'u' = unpause, 'pl' = play 's' = stop, 'q' = quit").strip().lower()
        if n == 'p':
            mp3.pause()
        elif n == 'u':
            mp3.unpause()
        elif n == 'pl':
            mp3.play()
        elif n == 's':
            mp3.stop()
        elif n == 'q':
            break
        else:
            break
    

    You could also put all of the valid answer options into a dictionary, but it looks like you should start with the simple solution to understand the flow. Also you used a p for both play and pause. You will want to use a unique value to differentiate so I added ‘pl’ for play.

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

Sidebar

Related Questions

I want to write data analysis plugins for a Java interface. This interface is
Is there a way to write interface-based code (i.e. using interfaces rather than classes
I wrote a process explorer using C with GUI interface. I want to add
I want to write a java program that acts as a user interface to
I want write a little code analyzer which parses nested structures and translates into
I've written an interface which is implemented by multiple classes. I want to write
I have an existing C# application. What I want is to write native code
I want to write (in PHP) a custom web interface over a CMIS repository.
I want to send temperature value from a microcontroller using UART to C# interface
I want write a simple query which will fetch data from a table (which

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.