Alan Gilfoy wrote: > 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"?
You could have a string containing all the allowed characters and make sure each input character is in the allowed list. > > 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? Lists and strings are both sequences and many of the same operations work on both. (All of the immutable sequence operations work on both.) So MyString[0] is the first character in 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") s[2] > "What's before that character?" (returns "C") s[1] or maybe s[2-1] if the 2 is actually in a variable. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor