#Get user input a = int(input("Enter the first number: ")) b = int(input("Enter the second number: ")) c = int(input("Enter the third number: ")) small = 0 middle = 0 large = 0 # IF Statement #SMALL if a < b and a < c: small = a elif b < a and b < c: small = b else: small = c #MIDDLE if (a < b and b < c) or ( c < b and b < a): middle = b elif( b < a and a < c )or (c < a and a < b): middle = a elif (a < c and c < b) or (b < c and c < a)we: middle = c #LARGE if a > b and a > c: large = a elif b > a and b > c: large = b else: large = c # Display Results print("The numbers in accending order are: ", large, middle, small)
[split] Manual Sort without Sort function
[split] Manual Sort without Sort function
|
Jun-01-2019, 05:43 PM
I've split your post into a separate thread so as to not cause notifications on a ~2 year old thread. With that in mind, were you trying to complete the OP's homework, or were you trying to ask a question?
Jun-02-2019, 06:13 AM
Nice Sunday morning wakeup exercise for the brain
![]() In my mind there is only three comparisons needed to order three numbers: compare two numbers and find their order; then find third numbers position (it can be either before first, before second or at the end) by comparing if it's smaller than first or second number, if not then it's largest. >>> a = 5 >>> b = 10 >>> c = 2 >>> lst = [] >>> if a < b: ... lst.extend([a, b]) ... else: ... lst.extend([b, a]) ... >>> lst [5, 10] >>> if c < lst[0]: ... lst.insert(0, c) ... elif c < lst[1]: ... lst.insert(1, c) ... else: ... lst.append(c) ... >>> lst [2, 5, 10]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame. |
|
Users browsing this thread: 2 Guest(s)