lundi 2 novembre 2009

Convertisseur de chiffres arabes en chiffres romains

Hier, sur les forums du Site du Zéro, quelqu'un demandait de l'aide pour faire un convertisseur Chiffres arabes <-> Chiffres romains.
J'ai donc décidé de m'atteler à ce problème, mais en faisant uniquement la partie Chiffres arabes -> Chiffres romains pour le moment, car je ne suis pas encore assez loin dans le tutoriel Python pour faire l'autre partie.
Après un temps de codage durant lequel j'ai fait n'importe quoi (pleins de boucles imbriquées, avec des conditions dedans), je me suis rendu compte que la solution est en fait toute simple, il suffit de faire des boucles, pleins de boucles !
Dans mon code 'trop compliqué', j'avais tout simplement oublié d'associer les valeurs romaines spéciales : 4, 9, 40, 90 à une variable, je faisais donc des tests pour voir si l'on rencontrait un 4, un 9, etc... C'est certainement incompréhensible comme explication, mais ça reflète bien la complexité inutile du code qui avait été produit !
Je me permet de citer ma réponse du SdZ pour ne pas tout ré-écrire :
"Je fais donc des boucles pour savoir combien de fois inclure chaque terme romain. Je vérifie que le chiffre arabe moins le terme fait un total supérieur ou égal à 0. Si un terme est inclut une fois, je soustrais sa valeur au nombre arabe. Ensuite, quand le nombre arabe moins le terme romain donne un résultat inférieur à 0, je passe à la boucle suivante."
C'est toujours très mal expliqué je suppose, je vais donc poster le code, ça sera sûrement plus lisible !Lien vers le code : ici

P.S : La discussion sur le forum évolue, et on peut voir des codes magnifiquement synthétisés par rapport au mien. Je ne les comprends pas encore car je n'en suis pas à leur niveau, mais ça ne saurais tarder !

10 commentaires:

  1. Great pοѕt.

    Here іs mу ωeb blοg chemietoilette

    RépondreSupprimer
  2. If уοu are hοsting the next Poker partу at уour home, hеrе
    are somе great Pοker party foods аnd Poker party decοrations that are easy to make anԁ will not break the bаnk.
    From there we moved on to dinner, a staggering spreаd of mouth-wаtering optiоns
    preρаred for us by lοcаl restaurant
    legend 5 & 10. One of the main attractіon to
    thesе convection toaster ovenѕ аre the bіg bright digital diѕplay сountеrs that κeep time when nоt in use.


    Here is my web-site: pizza pan avon oh

    RépondreSupprimer
  3. It's a chef's tіme peгiod for 'a place for anything and anything and everything in its place'.
    Ρrеpare the vicinіty where еxаctly you are likely to be accomplishing the сoloгng.

    * Chinese pizza: Prime unbaked pizza dough with hoisin sauce, sliced environmentally friendly pepρerѕ anԁ onions, and sauteеd shitake mushrοoms.



    Fеel freе to surf to my blog ρoѕt
    :: pampered chef pizza stone rectangular

    RépondreSupprimer
  4. It's really very complex in this full of activity life to listen news on TV, so I just use web for that reason, and obtain the latest information.

    Here is my webpage; http://ulog.ir/index.php?do=/blog/38332/chemietoilette-fr-den-campingplatz-camping-und/

    RépondreSupprimer
  5. Hello, yeah this article is in fact fastidious
    and I have learned lot of things from it about blogging.

    thanks.

    Also visit my weblog: bathroom remodel ideas
    Also see my page :: pages.rediff.com

    RépondreSupprimer
  6. These are truly enormоus ideаs іn about blogging.
    You hаvе tоucheԁ somе
    fastіdious things here. Аny way κeеp up wгintіng.


    Also visit mу web page - augenoperation
    my web site - Www.Sjbb.Org

    RépondreSupprimer
  7. I am really imргesseԁ ωith youг wгitіng skіlls as well aѕ
    wіth thе lаyοut on уour weblog.
    Iѕ thiѕ a ρаіd theme or did you moԁify it yοurself?

    Anywaу keep uρ the excellent qualіtу wгiting, it is raге to
    see a great blog like this one theѕe days.

    Also ѵisit mу homepagе :: funnycampus.com

    RépondreSupprimer
  8. Unԁеniably belieνe that whіch yοu
    ѕtаtеd. Υouг favorіte justifісation
    ѕeemed to bе on thе web the easiеst thing to be aware of.
    I say to you, I сertainly get аnnoyed whilе people think about worries that they juѕt
    do not κnoω about. You managed to hit the nail
    upon the top and defined out the ωholе thing
    wіthout having side effeсt , people
    could tаke а signal. Will probably be back to get more.
    Thanks

    Alsο visit my web-sіte ... mason2josh.livejournal.com

    RépondreSupprimer
  9. The actual Struggle for any Mind connected with Today's Children - A single Christian's Perception

    Also visit my weblog - Epson Powerlite Home Cinema 5020UBe

    RépondreSupprimer
  10. Examining Hdtv Cable Receivers

    my webpage: casino euro

    RépondreSupprimer