[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Fw: Undeliverable Message

Matthew_WARREN

1/31/2008 6:06:00 PM






> Heres the code
>
> def increment(digits,symbols):
>         overflow=True
>         digitpos=-1
>         while overflow and -digitpos<=len(digits):
>                 digitsymbolindex=symbols.index(digits[digitpos])
>                 if digitsymbolindex==len(symbols)-1:
>                         overflow=True
>                         digits[digitpos]=symbols[0]
>                         digitpos=digitpos-1
>                 else:
>                         digits[digitpos]=symbols[digitsymbolindex+1]
>                         overflow=False
>         return digits
>
> Now, this works. All good. It's nice and simple.  I'm just wondering how
> anyone else might approach it?

>I (not an expert at all) have only minor comments and one question:
>comments:
>why keep setting overflow to True, if you do not touch it will not
>change.


good point.


>digitpos -= 1 is easier to read in my mind

it's just something ive done for years, so I read it perfectly fine. It's
cause I was programming for ages before I first ever saw -= or += (bbc
basic didnt have 'em ;P)


>question:
>Why first extract the indices and then compare (in your if statement),
>and
>why do you not just compare the symbols?

I put the index into digitsymbolindex because it is used in more than one
place in the code, and I'd rather have the result stored than recompute it
possibly twice.

have fun!
Matt.
--
http://mail.python.org/mailman/listinfo/p...



This message and any attachments (the "message") is
intended solely for the addressees and is confidential.
If you receive this message in error, please delete it and
immediately notify the sender. Any use not in accord with
its purpose, any dissemination or disclosure, either whole
or partial, is prohibited except formal approval. The internet
can not guarantee the integrity of this message.
BNP PARIBAS (and its subsidiaries) shall (will) not
therefore be liable for the message if modified.
Do not print this message unless it is necessary,
consider the environment.

---------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le
"message") sont etablis a l'intention exclusive de ses
destinataires et sont confidentiels. Si vous recevez ce
message par erreur, merci de le detruire et d'en avertir
immediatement l'expediteur. Toute utilisation de ce
message non conforme a sa destination, toute diffusion
ou toute publication, totale ou partielle, est interdite, sauf
autorisation expresse. L'internet ne permettant pas
d'assurer l'integrite de ce message, BNP PARIBAS (et ses
filiales) decline(nt) toute responsabilite au titre de ce
message, dans l'hypothese ou il aurait ete modifie.
N'imprimez ce message que si necessaire,
pensez a l'environnement.