Ah, nice! Thank you! Sseeing the formal rules makes it easier: 
http://www.diveintopython.net/unit_testing/stage_5.html
A regex is used to test whether the roman numeral is valid. Very elegant!

 
Regards,
Albert-Jan


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 


>________________________________
> From: Evert Rol <[email protected]>
>To: Albert-Jan Roskam <[email protected]> 
>Cc: Python Tutor <[email protected]> 
>Sent: Monday, February 27, 2012 5:42 PM
>Subject: Re: [Tutor] roman to arabic
> 
>> 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
>> 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?
>
>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
>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.
>
>Hope that helps,
>
>  Evert
>
>
>
>>  
>> Regards,
>> Albert-Jan
>> 
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> All right, but apart from the sanitation, the medicine, education, wine, 
>> public order, irrigation, roads, a 
>> fresh water system, and public health, what have the Romans ever done for us?
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
>> From: Alan Gauld <[email protected]>
>> To: [email protected] 
>> Sent: Monday, February 27, 2012 4:37 PM
>> Subject: Re: [Tutor] roman to arabic
>> 
>> On 27/02/12 14:41, Cranky Frankie wrote:
>> 
>> > <<A quote worth mentioning here is:  "If you need more than 3 levels
>> > of indentation, you're screwed
>> > 
>> > I've always wondered about this quote. I'm thinking it means you might
>> > want to have functions or subroutines, depending on the language, to
>> > do big chunks of logic,
>> 
>> That's one option.
>> 
>> The OP also had the option of using a lookup table(dictionary)
>> or just using elifs instead of nested ifs.
>> 
>> Often a different algorithm helps.
>> 
>> 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.)
>> 
>> Simple hiding of indentation levels inside a function is kind of
>> the last resort in reducing indentation levels. Generally deep indentation 
>> reveals problems in the basic algorithm and/or
>> data structures.
>> 
>> > offers almost unlimited indentation, so it's up to the programmer to
>> > not use it?
>> 
>> Correct, this is a program design decision not a language feature.
>> 
>> -- Alan G
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>> 
>> _______________________________________________
>> Tutor maillist  -  [email protected]
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>> 
>> 
>> _______________________________________________
>> Tutor maillist  -  [email protected]
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
>
>
>
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to