On Sat, 1 Sep 2018 10:11:59 -0700 (PDT), moha...@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
Assuming this is homework, here's a hint: Instead of "5 90 63 82 59 24", feed it "2 1111", or "1 099999" or "1 2 3 ." (yes, "."). As a stylistic matter, looping over an array's indices is more cumbersome than looping over the elements of the array ("for x in arr:"), unless you actually need the index for something, which you don't. Also, two of the three arguments you pass to range can be omitted. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list