Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to manually sort a list of numbers in Python?
    primarykey
    data
    text
    <p>Specs: Ubuntu 13.04, Python 3.3.1 </p> <p>Background: total beginner to Python, came across this "manual sorting" problem. </p> <p>What I was asked to do: "Have the user enter 3 numeric values and store them in 3 different variables. Without using lists or sorting algorithms, manually sort these 3 numbers from smallest to largest." </p> <p>What I was able to come up with: </p> <pre><code>number = input("Please enter 3 numbers: ") number = list(number) a = int(number[0]) b = int(number[1]) c = int(number[2]) new_l = [] if a &gt; b and a &gt; c: new_l.append(a) if b &gt; c: new_l.append(b) new_l.append(c) else: new_l.append(c) new_l.append(b) print(new_l) if b &gt; a and b &gt; c: new_l.append(b) if a &gt; c: new_l.append(a) new_l.append(c) else: new_l.append(c) new_l.append(a) print(new_l) if c &gt; a and c &gt; b: new_l.append(c) if a &gt; b: new_l.append(a) else: new_l.append(b) new_l.append(a) print(new_l) </code></pre> <p>So my question is: I realize that my solution is extremely limited. First it can only process 3 single digit numbers since once the input string is converted into a list, there is no way to break all digits correctly into individual numbers the user intended. Second,by using this solution, the coder is forced to enumerates all possible scenarios for the 3 numbers to compare with each other, which could be very inflexible if say, the script were to be changed to accepting user input of 100+ numbers.</p> <p>If you could share some guidance regarding the question above, or regarding how to solve this problem in a different way, I'll be very greatful! Thank you. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload