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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:42:04+00:00 2026-05-14T04:42:04+00:00

My question is, why are these expressions False? Python 2.6.4 (r264:75706, Dec 7 2009,

  • 0

My question is, why are these expressions False?

Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> num = raw_input("Choose a number: ")
Choose a number: 5
>>> print num
5
>>> print ( num < 18 )
False
>>> print ( num == 5 )
False

Because if i try this:

>>> print ( num > 0 )
True

The expression works fine.

  • 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-14T04:42:04+00:00Added an answer on May 14, 2026 at 4:42 am

    This statement:

    num = raw_input("Choose a number: ")
    

    makes num a string, not a number, despite its misleading name. It so happens that Python 2 lets you compare strings with numbers, and in your version considers all strings larger than all numbers (the contents of the string play no role).

    Use num = int(num) to make an integer (and be sure to use a try/except to catch possible errors when the user has typed something other than a number!) before you start comparing.

    (In Python 3, the function’s name changes from raw_input to input, and it still returns strings; however in Python 3 comparing a string with a number is considered an error, so you would get an exception rather than True or False in each of your comparison attempts).

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

Sidebar

Related Questions

This may be a lame question but I am a total novice with regular
This might be a silly question, but: Suppose an expression depends only on literals,
While answering this question regarding safe escaping of filename with spaces (and potentially other
Executive Summary: preg_replace() ran faster than string comparisons. Why? Shouldn't regular expressions be slower?
The goal Today's Code Golf challenge is to create a regex parser in as
I am getting all events, with a certain attribute, and I want to modify
I'm currently working on a problem with a custom UserControl, I want to expose
Hey, I wrote this (fortran) with the aim of finding the minimum spanning tree
I've got a simple grammar. Actually, the grammar I'm using is more complex, but
The two posts below are great examples of different approaches of extracting data from

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.