python - Using a Scanner Loop -


i have file contains numbers 11 5 3 51, im trying use scanner read file , print out smallest number in file. reason when run program below keeps saying "the smallest number 7" lol , im consued program getting number 7 from? there isnt number 7 in file or program matter.....what issue?

from scanner import*   def main():     s = scanner("data.txt")     items = ("data.txt")     = s.readint()     ismallest = 0     in range(0,len(items),1):         if (items[i] < items[ismallest]):             ismallest =     print ("the smallest number is", i)  main() 

here's how i'd open instead of scanner

content = []; open("input.txt") f:   content = f.readline().split()  ismallest = int(content[0])  in range(0,len(content),1):   if (int(content[i]) < ismallest):     ismallest = int(content[i])  print ("the smallest number is", ismallest) 

edit: ok, think should work if want use scanner:

s = scanner("data.txt") items = [] currentint = s.readint()  while currentint:     items.append(currentint)     currentint = s.readint()  ismallest = items[0]  in range(0,len(items),1):   if (items[i]) < ismallest):     ismallest = items[i]  print ("the smallest number is", ismallest) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -