<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>Ah, nice! Thank you! S</span><span>seeing the formal rules </span><span>makes it easier: http://www.diveintopython.net/unit_testing/stage_5.html</span></div><div><span>A regex is used to test whether the roman numeral is valid. Very elegant!<br></span></div><div>&nbsp;</div><div>Regards,<br>Albert-Jan<br><br></div><div>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a <br>fresh water system, and public health, what have the Romans ever done for us?<br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&nbsp;<br> <blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;">  <div style="font-family: times new roman,
 new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> <hr size="1">  <b><span style="font-weight:bold;">From:</span></b> Evert Rol &lt;evert.rol@gmail.com&gt;<br> <b><span style="font-weight: bold;">To:</span></b> Albert-Jan Roskam &lt;fomcl@yahoo.com&gt; <br><b><span style="font-weight: bold;">Cc:</span></b> Python Tutor &lt;tutor@python.org&gt; <br> <b><span style="font-weight: bold;">Sent:</span></b> Monday, February 27, 2012 5:42 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [Tutor] roman to arabic<br> </font> </div> <br>
&gt; I wrote a little program that does the conversion (I won't post it because it would be a spoiler for the OP). The one thing I don't know, though, is how to formalise<br>&gt; that it is not allowed to write something like IIIIIIIIX, but instead just II. Or not DM but simply D. The rule is to write it the shortest possible way. Am I wrong or is it really not trivial at all to write an error class for such lengthy roman numerals?<br><br>Mark Pilgrim wrote whole sections on Roman numerals in his Dive Into Python tutorial. While the numerals pop up in various examples throughout the chapters of the tutorial, for this, the tutorial on unit testing may proof helpful: http://www.diveintopython.net/unit_testing/romantest.html<br>Somewhere in that example, there's unit testing code just for examples as above. From the unit test, follow the tutorial into chapter 14 to see how it's done.<br><br>Hope that helps,<br><br>&nbsp; Evert<br><br><br><br>&gt;&nbsp;
 <br>&gt; Regards,<br>&gt; Albert-Jan<br>&gt; <br>&gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&gt; All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a <br>&gt; fresh water system, and public health, what have the Romans ever done for us?<br>&gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <br>&gt; From: Alan Gauld &lt;<a ymailto="mailto:alan.gauld@btinternet.com" href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>&gt;<br>&gt; To: <a ymailto="mailto:tutor@python.org" href="mailto:tutor@python.org">tutor@python.org</a> <br>&gt; Sent: Monday, February 27, 2012 4:37 PM<br>&gt; Subject: Re: [Tutor] roman to arabic<br>&gt; <br>&gt; On 27/02/12 14:41, Cranky Frankie wrote:<br>&gt; <br>&gt; &gt; &lt;&lt;A quote worth mentioning here is:&nbsp; "If you need more than 3 levels<br>&gt; &gt; of indentation, you're screwed<br>&gt;
 &gt; <br>&gt; &gt; I've always wondered about this quote. I'm thinking it means you might<br>&gt; &gt; want to have functions or subroutines, depending on the language, to<br>&gt; &gt; do big chunks of logic,<br>&gt; <br>&gt; That's one option.<br>&gt; <br>&gt; The OP also had the option of using a lookup table(dictionary)<br>&gt; or just using elifs instead of nested ifs.<br>&gt; <br>&gt; Often a different algorithm helps.<br>&gt; <br>&gt; Also functional programming (ie. not just procedural!) can reduce the numbers of indentation levels. (See the FP topic in my tutor for some examples of this.)<br>&gt; <br>&gt; Simple hiding of indentation levels inside a function is kind of<br>&gt; the last resort in reducing indentation levels. Generally deep indentation reveals problems in the basic algorithm and/or<br>&gt; data structures.<br>&gt; <br>&gt; &gt; offers almost unlimited indentation, so it's up to the programmer to<br>&gt; &gt; not use it?<br>&gt;
 <br>&gt; Correct, this is a program design decision not a language feature.<br>&gt; <br>&gt; -- Alan G<br>&gt; Author of the Learn to Program web site<br>&gt; http://www.alan-g.me.uk/<br>&gt; <br>&gt; _______________________________________________<br>&gt; Tutor maillist&nbsp; -&nbsp; <a ymailto="mailto:Tutor@python.org" href="mailto:Tutor@python.org">Tutor@python.org</a><br>&gt; To unsubscribe or change subscription options:<br>&gt; http://mail.python.org/mailman/listinfo/tutor<br>&gt; <br>&gt; <br>&gt; _______________________________________________<br>&gt; Tutor maillist&nbsp; -&nbsp; <a ymailto="mailto:Tutor@python.org" href="mailto:Tutor@python.org">Tutor@python.org</a><br>&gt; To unsubscribe or change subscription options:<br>&gt; <a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br><br><br><br> </div> </div> </blockquote>  </div></div></body></html>