[Tutor] Help with Max Number and Min number script
Alan Gauld
alan.gauld at yahoo.co.uk
Sat Sep 17 20:20:10 EDT 2016
On 17/09/16 00:08, Sharon Wallace wrote:
> inp = raw_input
> largest = None
> smallest = None
>
> while True:
> num = raw_input('Enter a number: ')
> if num = 'done' : break
> print num
> try :
> num = float(inp)
> except :
> print 'Invalid input'
> continue
While some whitespace is good, too much is as bad as none.
I've removed most of the blank lines but your indentation
levels are way too big. Also they are inconsistent and
in some places wrong. Indentation is crucially important
in Python.
Your code above should look like:
largest = None
smallest = None
while True:
num = raw_input('Enter a number: ')
if num = 'done' :
break
print num
try :
num = float(inp)
except :
print 'Invalid input'
continue
That uses the recommended 4 spaces indentation and makes it
much easier to see what is going on.
hth
--
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