[Tutor] Roman to digital (pseudocode)
Alan Gilfoy
agilfoy at frontiernet.net
Thu Mar 8 17:01:58 CET 2007
This, I heard, is more difficult than digital-to-Roman, since you have
to "read" the subtractive cases, with a smaller numeral placed before
a larger numeral, without simply adding all the numerals' values up
I'm going to use a raw_input prompt to ask the user which Roman
numeral he/she wants to convert. How do I "screen" for inputs that
have characters besides "I", "V", "X", "L", "C", "D", or "M"?
Second Python question:
I know there's a way to "find out" the name of the first item in a list
(ListName[0]), but is there a way to find out the first character of a string?
Also, is there a way to "ask" Python what characters are before and
after the character in the string that you're asking about?
For example, usign the sample string "MCMXVII" (1917):
How would you ask Python:
"What's the 3rd character in this string?" (returns "M")
"What's before that character?" (returns "C")
Pseudocode time:
If character Y is "M":
and the character before character Y is "C",
add 900 to digital_result
and remove that "C" and that "M" from the string.
#How would you do *that*?
and the character before character Y is another "M", or if character Y
is the first character in the string,
add 1000 to digital_result
and remove that "M" from the string.
More information about the Tutor
mailing list