[Tutor] manually sorting variables
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:
if x < y:
elif y < x:
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)
smallest = smallest_var(small, var3)
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."
"Who dares wins"
-British military motto
"I generally know what I'm doing."
More information about the Tutor