Help Needed : script weird result.

Joel Goldstick joel.goldstick at gmail.com
Sat Sep 1 13:29:59 EDT 2018


On Sat, Sep 1, 2018 at 1:26 PM duncan smith <duncan at invalid.invalid> wrote:
>
> On 01/09/18 18:11, mohan4h at gmail.com wrote:
> > All,
> >
> > I m trying to run this small script to find the lowest of the given array of numbers. The script works fine for various combination of inputs but fails in a weird way for a particular set of inputs, can anyone point the mistake in the script and the behavior.
> >
> > Script
> >
> > x = input ("Enter the numbers separated by space and press ENTER :")
> > x = x.split(" ")
> >
> > def checkmin(arr):
> >     lowest = arr[0]
> >     for count in range(0,len(arr),1):
> >         if arr[count] < lowest :
> >             lowest = arr[count]
> >         else :
> >             pass
> >         print (lowest)
> >     return lowest
> >
> > minimum = checkmin(x)
> > print ("Lowest : {0}".format (minimum))
> >
> >
> > Weird output is as below.
> >
> > ================== RESTART: C:\Users\mohan\Desktop\temp.py ==================
> > Enter the numbers separated by space and press ENTER :5 90 63 82 59 24
> > 5
> > 5
> > 5
> > 5
> > 5
> > 24
> > Lowest : 24
> >
> > Regards
> > Mohan C
> >
>
>
> Compare,
>
> >>> min(5, 90, 63, 82, 59, 24)
> 5
> >>> min('5', '90', '63', '82', '59', '24')
> '24'
> >>>
>
> Duncan
> --
> https://mail.python.org/mailman/listinfo/python-list

integers are not strings.  Strings collate according to alphanumeric
sequence.  So the 2 in 24 makes it less than the 5


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays



More information about the Python-list mailing list