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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:30:15+00:00 2026-06-13T16:30:15+00:00

I tried to search for this error, but i didnt find it so here

  • 0

I tried to search for this error, but i didnt find it so here it is:

I try to enter input in a python 3 script running in linux, which can only be 0-5.
I do this using the following code:

    while True:
        type = input("Please choose a type:\n1) a\n2) b\n3) c\n4) d\n0) EXIT\n"))

        if type == "0":
            sys.exit()

        elif type == "1" or type == "2" or type == "3" or type == "4":
            print("You entered: %s" %type )
            break

        else:
            os.system("clear")
            print("Input entered is invalid, please try again.\n")

The program runs fine when I enter numbers, but when I enter a letter it crashes.
Please help 🙁

Traceback (most recent call last):
  File "test.py", line 21, in <module>
    type = input("Please choose a type:\n1) a\n2) b\n3) c\n4) d\n0) EXIT\n"))   
  File "<string>", line 1, in <module>
NameError: name 'h' is not defined
  • 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-13T16:30:17+00:00Added an answer on June 13, 2026 at 4:30 pm

    input is equivalent to eval(raw_input(prompt))

    Meaning your input is interpreted. Meaning that number, function, var will work, but not text.

    Use raw_input instead. (see http://docs.python.org/2/library/functions.html#raw_input )

    Nota: this is valid python 2, and you mention python 3. However, I think you are actually using python 2, as your prompt ends with a \n, which is included in python 3, and as your script works on python 3

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

Sidebar

Related Questions

I've search here for an answer to this error & I've tried the tips
Hi i tried to search an answer in google but i didnt find even
i tried to search this but was not able to get any proper help.I
I've tried to search for a solution for this, but have had no joy:
I have tried to search for an answer in google, and this site, but
I've tried searching through search engines,MSDN,etc. but can't anything. Sorry if this has been
I've tried to search for similar problems, but can't seem to find it. I
Tried to search for this online and didn't get very far, so I'm asking
tried to search for this, although I am not even sure what I am
I tried to search and found this: Sort an array by a child array's

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.