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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:09:34+00:00 2026-06-09T00:09:34+00:00

I’m trying to learn how to program and I’m running into a problem…. I’m

  • 0

I’m trying to learn how to program and I’m running into a problem….

I’m trying to figure out how to make sure someone inputs a number instead of a string. Some related answers I found were confusing and some of the code didn’t work for me. I think someone posted the try: function, but it didn’t work, so maybe I need to import a library?

Here’s what I’m trying right now:

Code:

print "Hi there! Please enter a number :)"
numb = raw_input("> ")

if numb != str()
    not_a_string = int(next)
else:
    print "i said a number, not a string!!!"

if not_a_string > 1000:
    print "You typed in a large number!"

else:
    print "You typed in a smaller number!"

Also I have another question while I’m asking. How can I make it so it will accept both uppercase and lower case spellings? In my code below, if I were to type in “Go to the mall” but with a lowercase G it would not run the if statement because it only accepts the capital G.

print "What would you like to do: \n Go to the mall \n Get lunch \n Go to sleep"
answer = raw_input("> ")

if answer == "Go to the mall":
    print "Awesome! Let's go!"
elif answer == "Get lunch":
    print "Great, let's eat!"
elif answer == "Go to sleep":
    print "Time to nap!"
else:
    print "Not what I had in mind...."

Thanks. ^^

Edit: I’m also using python 2.7 not 3.0

  • 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-09T00:09:37+00:00Added an answer on June 9, 2026 at 12:09 am

    You can do something like this:

    while True: #infinite loop
       ipt = raw_input(' Enter a number: ')
       try:
          ipt = int(ipt)
          break  #got an integer -- break from this infinite loop.
       except ValueError:  #uh-oh, didn't get an integer, better try again.
          print ("integers are numbers ... didn't you know? Try again ...")
    

    To answer your second question, use the .lower() string method:

    if answer.lower() == "this is a lower case string":
       #do something
    

    You can make your string comparisons really robust if you want to:

    if answer.lower().split() == "this is a lower case string".split():
    

    In this case, you’ll even match strings like “ThIs IS A lower Case\tString”. To get even more liberal in what you accept, you’d need to use a regular expression.

    (and all this code will work just fine on python2.x or 3.x — I usually enclose my print statements in parenthesis to make it work for either version).

    EDIT

    This code won’t quite work on python3.x — in python3, you need to change raw_input into input to make it work. (Sorry, forgot about that one).

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.