0
num1 = input("enter number 1:")
num2 = input("enter number 2:")
num3 = input("enter number 3.")
small = 0
mid = 0
larg = 0

if num1 < num3 and num1 < num2:
    small = num1
    if num2 < num3 and num2 < num1:
        small = num2
    else:
        small = num3

elif num1 < num2 and num1 < num3:
    mid = num1
    if num2 > num1 and num2 < num3:
        mid = num2
    else:
        mid = num3

elif num1 > num2 and num1 > num3:
    larg = num1
    if num2 > num1 and num2 > num3:
        larg = num2
    else:
        larg = num3

print(small,mid,larg)

When I run and input numbers 100 200 & 300, console shows 300 0 0.

Thierry Lathuille
  • 23,663
  • 10
  • 44
  • 50
  • 2
    Post the code, do not post images of the code – Adirio Sep 04 '19 at 09:30
  • 3
    Unless you are on python 2.x, `input()` returns a string - and you compare strings. please [edit] your questions and format your code. You need to convert strings tro numbers - google it. Your comparisonst do not match: if num1 is smaller then num3 and num2 then num2 cannot be smaller num1: `if num1 < num3 and num1 < num2: ... if num2 < num3 and num2 < num1:`. Your logic is faulty. – Patrick Artner Sep 04 '19 at 09:34

3 Answers3

1

Simple method:

num1 = int(input('Enter num 1: '))
num2 = int(input('Enter num 2: '))
num3 = int(input('Enter num 3: '))

small, mid, large = sorted([num1, num2, num3])
print(small, mid, large)

More manual method

def smallest(x, y, z):
  if x < y and x < z:
    return x
  elif y < x and y < z:
    return y
  else:
    return z

def largest(x, y, z):
  if x > y and x > z:
    return x
  elif y > x and y > z:
    return y
  else:
    return z

def middle(x, y, z):
    if x < y:
        if y < z:
            return y
        elif x < z:
            return z
        else:
            return x
    else:
        if x < z:
            return x
        elif y > z:
            return y
        else:
            return z

small = smallest(num1, num2, num3)
large = largest(num1, num2, num3)
mid = middle(num1, num2, num3)

print(small, mid, large)

Other Methods: How to manually sort a list of numbers in Python?

DarrylG
  • 16,732
  • 2
  • 17
  • 23
0
num1 = input("enter number 1:")
num2 = input("enter number 2:")
num3 = input("enter number 3.")
small = 0
mid = 0
larg = 0

if num1 < num3 and num1 < num2:
    small = num1
    if num2 < num3 and num2 < num1:
        small = num2
    else:
        small = num3

elif num1 < num2 and num1 < num3:
    mid = num1
    if num2 > num1 and num2 < num3:
        mid = num2
    else:
        mid = num3

elif num1 > num2 and num1 > num3:
    larg = num1
    if num2 > num1 and num2 > num3:
        larg = num2
    else:
        larg = num3
print(small,mid,larg)
0
num1 = int(input("enter number 1:"))
num2 = int(input("enter number 2:"))
num3 = int(input("enter number 3."))
small = 0
mid = 0
larg = 0

if num1 < num3 and num1 < num2:
    small = num1
elif num2 < num3 and num2 < num1:
    small = num2
else:
    small = num3

if num1 < num3 and num1 > num2:
    mid = num1
elif num2 < num1 and num2 > num3:
    mid = num2
else:
    mid = num3

if num1 > num2 and num1 > num3:
    larg = num1
elif num2 > num1 and num2 > num3:
    larg = num2
else:
    larg = num3
print(small,mid,larg)

There were issues in conditions I have corrected it hopefully it will work.

Vashdev Heerani
  • 660
  • 7
  • 21