[Tutor] input() and raw_input()
Thu, 8 Feb 2001 11:39:28 -0500
On Thu, Feb 08, 2001 at 11:20:54AM -0500, Henry wrote:
> I'm taking a number as input from the user and attempting to do a
> comparison on it:
> selection = raw_input('Enter number: ')
> if selection < 3:
> print 'Invalid number'
> print 'OK number'
> The comparison works using input() but doesn't when using
> raw_input() -- it always drops to the 'else:'.
> I was trying to use raw_input() because it was recommended in the
> documentation as a safer way to get user input. What exactly is
> raw_input() doing to the input?
Nothing. That's why it's called *raw*_input(). And that's where your
problem lies. raw_input() returns a string which you are then comparing
to a number. You need to convert 'selection' to a numeric variable.
"Moderation in temper is always a virtue; but moderation in
principle is always a vice."
-- Thomas Paine, _The Rights of Man_ (1791)
Rick Pasotto email: firstname.lastname@example.org