0

why the min() function doesn't work here? help

in this code i wrote, if you input two or more numbers, the min() function gives "no input", whilst the max() gives you the expected result... i=input('') list(i) print(min(i)) print(max(i)) could you please explain me why? thanks (with only one number the min() works though)

7th Oct 2019, 8:00 PM
Luca
Luca - avatar
9 Respuestas
+ 5
if you use this instead your input statement, it does work also for numbers > 9: i = [int(i) for i in input('enter values sep by comma:').split(',')] #result: enter values sep by comma:0,14,6,2,3,-4 -4 14
7th Oct 2019, 8:53 PM
Lothar
Lothar - avatar
+ 2
thank you Lothar!!
7th Oct 2019, 9:01 PM
Luca
Luca - avatar
+ 2
if you'r imputing all the numbers in one input as a string e.g 1 4 23 54 (just a space in between).. then:- print(min(i.split())) print(max(i.split())) if you'r imputing all the numbers in one input as a string e.g 1, 4, 23, 54 (with a comma in between)..then print(min(i.split(','))) print(max(i.split(',')))
7th Oct 2019, 9:25 PM
rodwynnejones
rodwynnejones - avatar
+ 1
this way it works, thank you Mirielle, i was typing a space between every number.. but what if i want to input a number >=10, how to make it count like one number and not two in a row
7th Oct 2019, 8:24 PM
Luca
Luca - avatar
+ 1
about the code value of a space , thank you rodwynnejones still i can't seem to find a way to input 10 as a single number.. i took a glance at the split method but i haven't understood how it could help in this case could you please give me a hint?
7th Oct 2019, 8:51 PM
Luca
Luca - avatar
+ 1
This code won't even work with 2 digit numbers i.e numbers greater than 9, because every thing is ok but the first line you worte i=input(") Which will not seprate numbers you input. The solution is you should separate the input by split() I have written a code for you in my profile and it works. Hope you will understand better after looking at my code. https://code.sololearn.com/c3OSFE7JNm3h/?ref=app
8th Oct 2019, 9:42 AM
Tasdiq Shaikh
Tasdiq Shaikh - avatar
0
your input is a string, and if you input a space, it has a lower character code than a number or alphabet character, so min print ' ', an empty string. just to add...the list(i) does nothing. Try doing i = list(i).
7th Oct 2019, 8:33 PM
rodwynnejones
rodwynnejones - avatar
0
look up string method 'split'. if you'r imputing all the numbers in one input eg 1 4 23 54 (just a space in between).. then:- print(min(i.split())) print(max(i.split()))
7th Oct 2019, 8:35 PM
rodwynnejones
rodwynnejones - avatar