+ 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
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))
+ 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)
+ 1
Seb TheS Thanksš„