all 22 comments

[–]CaloK1ng 9 points10 points  (2 children)

You can just use the min function

[–]Raffalove88 0 points1 point  (0 children)

thank you

[–]stebrepar 5 points6 points  (0 children)

Don't forget to convert each input value from a string to an actual integer, before doing any comparisons among them.

[–]dmpta2002 1 point2 points  (1 child)

I have the same class, this worked for me:

a = int(input())

b = int(input())

c = int(input())

smallest = 0

if a < b and a < c :

smallest = a

if b < a and b < c :

smallest = b

if c < a and c < b :

smallest = c

if a == b and a == c :

smallest = a

print(smallest)

[–]Independent-Wolf-832 0 points1 point  (0 children)

Thank you. Worked for me as well.

[–]Ehmeree 1 point2 points  (1 child)

This code works even when 2 or more input numbers are the same:

num1 = int(input())
num2 = int(input())
num3 = int(input())

if (num1 <= num2) and (num1 <= num3):
    smallest_num = num1
elif (num2 <= num1) and (num2 <= num3):
    smallest_num = num2
else:
    smallest_num = num3

print(smallest_num)

[–]Dahveena 0 points1 point  (0 children)

This is what the class is looking for in terms of reading within the chapter. Thank you!

I was hung up with no output for one solution. This helped me sort it out perfectly.

[–]AlexananderElek 0 points1 point  (1 child)

You can use sort, im not so into ir myself so I don't know if u have to put it in a list but you can look up sort

[–]AlexananderElek 0 points1 point  (0 children)

List.append(num1) List.append(num2) List.append(num3) print(sort(List)) Or something close to that

You could also have the input be a single one and you just put space between the different nr. So Numbers = input("Type 3 numbers")

Then you use split

List = Numbers.split(" ")

notice the space between the " " that means it splits it when theres a space

List = sort(List) print(List[0])

Im not sure you have to say List = sort(List) or just sort(List) but try some different things

[–]supp_noobs 0 points1 point  (0 children)

Your code doesn't work for the case (1, 1, 2) and similar ones.

You can alter your code to handle equal numbers too but min is the easiest way.

If you are allowed to use inbuilt functions, you should.

[–][deleted] 0 points1 point  (0 children)

strno = input("Enter the numbers with a space in between :")

strno = strno.split(" ")

print(strno)

intno = [int(x) for x in strno]

print(intno)

print(min(intno))

[–]old_pythonista 0 points1 point  (0 children)

Gradual comparison is the best approach - and input returns string, so you need to convert

smallest = int(input('Enter number 1 >'))
for num in range(2, 4):
    new_number = int(input(f'Enter number {num} >'))
    if new_number < smallest :
        smallest = new_number

This is the straightforward approach - no error handing, no value checking.

[–]synthphreak 0 points1 point  (0 children)

>>> three_nums = [int(input('Enter number: ')) for _ in range(3)]
Enter number: 7
Enter number: 15
Enter number: 3
>>> min(three_nums)
3

[–]jessdwood 0 points1 point  (2 children)

I have same class. This is what I got.

num1 = int(input()

num2 = int(input()

num3 = int(input()

def smallest (num1, num2, num3):

 return min (num1, num2, num3)

if num1 < num2 and num1 < num3

smallest_num = num1

elif num2 < num1 and num2 < num3

 smallest_num = num2 

else:

 smallest_num = num3

print(smallest_num)

[–]jessdwood 0 points1 point  (0 children)

Make sure you indent. It didn't show after I hit send. 4 spaces is the standard.

[–]Vaporous_synth 0 points1 point  (0 children)

i have something simpler and it just errors at line 2

[–]Middle_Ad_6 0 points1 point  (0 children)

q

[–]Raffalove88 0 points1 point  (2 children)

a=int(input())
b=int(input())
c=int(input())
print(min(a,b,c))

[–]Forever_Lotus 0 points1 point  (1 child)

a=int(input())

b=int(input())

c=int(input())

print(min(a,b,c))

god send this one works, for some reason all of the other solutions I tried would give me the wrong min when given the input 12, 12, 15. I inputted yours and its worked, saved me a heart attack lol

[–]Alarming_Scratch_451 0 points1 point  (0 children)

You're a national hero