[Tutor] Python Variables Changing in Other Functions

Alan Gauld alan.gauld at btinternet.com
Thu May 26 01:54:39 CEST 2011


"Rachel-Mikel ArceJaeger" <arcejaeger at gmail.com> wrote

I'm not sure I like this one much...

def rank( randomizedTitles, dictOfTitles ):
    """ Gets a user-input ranking (0-10) for each line of text. 
        Returns those rankings 
    """
    
    for title in randomizedTitles:
        
        while True:
            
            rank = raw_input(title + " ")
            
            if not rank.isdigit():
                continue
            elif ( int(rank) > 10 ):
                continue

I'd have made the while test do the checking:

rank = ''
while (not rank.isdigit() ) or ( int(rank) > 10 ):
       rank = raw_input(....)

And I'd have put the next line outside the while
               
            dictOfTitles[title].append(rank)

And you then don't need the break
            break

Just an opinion though,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list