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

  • Home
  • SEARCH
  • 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 6140541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:07:52+00:00 2026-05-23T18:07:52+00:00

I have 5 different strings i am searching for in a text file. I

  • 0

I have 5 different strings i am searching for in a text file. I am trying to get python to ask the user for a “room number” and if any of those numbers match, to continue, otherwise ask again until a correct number is entered.

I can get it to work if try:

roomNumber = input("Enter the room number: ")
while roomNumber != ("L1"):
    roomNumber = input ("Please enter a correct room number:")

However i wish to have a positive match for L1, L2, L3, L4, and L5.

I tried:

roomNumber = input("Enter the room number: ")
while roomNumber != ("L1", "L2", "L3", "L4", "L5"):
    roomNumber = input ("Please enter a correct room number:")

however this doesn’t work and i assume it wants all of those matches, not just the one.
I also tried putting each value in a ([ ]) and also tried using OR between each value but didn’t work either.

I’ve been searching for ages and can’t seem to find examples of multiple matches in a while loop.

Surely i’m missing something simple?

  • 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-23T18:07:53+00:00Added an answer on May 23, 2026 at 6:07 pm

    Python has an in/not in operator that is useful for things like this:

    while roomNumber not in ("L1", "L2", "L3", "L4", "L5"):
        ...
    

    It works for almost any container type in Python; all of the following are true:

    1 in [1, 2, 3]
    3 in range(50)
    "foo" in { "foo": "bar" }
    "bar" not in { "foo": "bar" } # (it only looks at keys for dictionaries)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that allows the user to either upload a text file
I have lots of strings containing text in lots of different spellings. I am
I have a website that has approx 1000 different strings in a mysql database
My application may have strings comprised of different alphabets / languages in a single
I have a string pc1|pc2|pc3| I want to get each word on different line
I have a text file and I want to be able to change all
I'm parsing an XML file which can contain localized strings in different languages (at
I have been searching the web for several hours to try to get an
I have two strings and would like to display the difference between them. For
I have different php output in jQuery-based tabs. This output is formed from database

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.