[Tutor] manually sorting variables

Christopher Spears cspears2002 at yahoo.com
Fri Sep 7 02:13:09 CEST 2007

I'm working out of Core Python Programming (2nd
Edition) by Wesley Chun.

Here is the problem:

Have the user enter three numeric values and store
them in three different variables.  Without using
lists or sorting algorithms, manually sort these three
numbers from smallest to largest.

Here is what I have so far:
#!/usr/bin/env python

def smallest_var(x,y):
	if x < y:
		return x
	elif y < x:
		return y
		print "x equals y"
var1 = raw_input("Enter a number for var1: ")
var2 = raw_input("Enter a number for var2: ")
var3 = raw_input("Enter a number for var3: ")

small = smallest_var(var1, var2)
#print small_var_1
smallest = smallest_var(small, var3)
print smallest

I'm not sure what the next step would be.  If I was
using a list, I could try to remove the smallest
variable and then just compare the two remaining
variables.  Any hints?

"I'm the last person to pretend that I'm a radio.  I'd rather go out and be a color television set."
-David Bowie

"Who dares wins"
-British military motto

"I generally know what I'm doing."
-Buster Keaton

More information about the Tutor mailing list