[Tutor] Help with Max Number and Min number script

Alan Gauld alan.gauld at yahoo.co.uk
Sun Sep 18 19:37:36 EDT 2016


On 17/09/16 00:08, Sharon Wallace wrote:
> largest = None
> smallest = None
> 
> while True:
>     num = raw_input('Enter a number:  ')
>     if num = 'done' : break

should use == to test equality a single = is
an assignment and would give an error here

         print num
         try :
             num = float(inp)
         except :

Don't use a bare except here, specify the error,
otherwise you potentially miss a lot of useful
debug information. Specifically you want to
catch ValueError here.

             print 'Invalid input'
             continue

       if largest is None or num > largest :
          largest = num
       if smallest is None or num < smallest :
          smallest = num

> print 'Maximum is:', largest
> print 'Minimum is:', smallest

Fix those errors and it should work

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list