+ 3

I need the largest element from the list. so i typed this programme but by taking string as "100.25,80.99,40.00"

it's giving me 80.99? how do i get 100.25?? a=str(input()).split(",") print(a) b=max(a) print(b) https://code.sololearn.com/c8SEsZ6FvKW2/?ref=app

3rd Mar 2020, 8:48 PM
Navneet
Navneet - avatar
3 Answers
+ 2
You're comparing strings. Strings are compared by their first alphabets and 1 from 100.25 is less than 8 in 80.99. You can fix this by converting all string numbers to floats: a = list(map(float, a))
3rd Mar 2020, 8:57 PM
Seb TheS
Seb TheS - avatar
+ 3
'80.99' > '100.25', because these are strings. If you want to compare them as floats you need to use an explicit cast: a=str(input()).split(",") print(a) a = [float(x) for x in a] b = max(a) print(b)
3rd Mar 2020, 8:58 PM
Š’Š»Š°Š“ ŠŠ½Ń‚ŠµŠµŠ²
Š’Š»Š°Š“ ŠŠ½Ń‚ŠµŠµŠ² - avatar
+ 1
Seb TheS ThanksšŸ”„
3rd Mar 2020, 8:59 PM
Navneet
Navneet - avatar