joshgachnang / diveintopython

A mirror of diveintopython.org.
157 stars 48 forks source link

Example 7.8. Validating Roman Numerals with {n,m} #65

Open hsmit opened 10 years ago

hsmit commented 10 years ago

This example (7.8) (and just before it in 7.7) the code contradicts the initial rules for Roman numbers. The rules state that "The tens characters (I, X, C, and M) can be repeated up to three times". However, in the regex of 7.7 it states 4 optional M's; "pattern = '^M?M?M?M?(CM|CD|D?C?C?C?)(XC|XL|L?X?X?X?)$'" Later on this is continued by M{0,4} which is wrong, right?

hsmit commented 10 years ago

in source: regular_expressions/n_m_syntax.html

farid67 commented 10 years ago

I think you're right, if we want to write 4000 in roman numeral we use a vertical bar with just IV below to say " 4 * 1000 " There is also a problem when they tried to convert 3888, they have used 4 recurrences of M but it should just have 3