Python Forum
[split] Manual Sort without Sort function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Manual Sort without Sort function
#1
#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)
Reply
#2
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?
Reply
#3
Nice Sunday morning wakeup exercise for the brain Smile

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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to sort a list with duplicates and return their unique indices. Echoroom 3 3,351 Sep-23-2022, 07:53 AM
Last Post: deanhystad
  sorting a list using unicodes acending order, no loops, no sort(), using recursion lrn2codee 14 6,243 Jun-23-2021, 07:33 PM
Last Post: deanhystad
  Sort and merge flintstone 1 1,870 Jun-14-2021, 07:32 PM
Last Post: Larz60+
  How can I sort my column so that NaN is at the bottom? soft 3 2,355 Feb-06-2021, 01:02 PM
Last Post: ibreeden
  how to sort a list without .sort() function letmecode 3 3,370 Dec-28-2020, 11:21 PM
Last Post: perfringo
  Sort on basis of (name,age,score) pyzyx3qwerty 9 9,405 May-14-2020, 08:29 AM
Last Post: pyzyx3qwerty
  Sort last pyzyx3qwerty 7 4,665 May-05-2020, 02:58 PM
Last Post: DeaD_EyE
  insertion sort brobro 3 2,156 Apr-24-2020, 01:29 PM
Last Post: Godserena
  [split] problem with function return value ops 1 3,275 Apr-13-2020, 01:48 PM
Last Post: buran
  Sort objects by protected properties. Sigriddenfeta 1 1,854 Mar-17-2020, 04:11 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020