The Journey of a New Computer Programmer

A longtime computer-literate who wants to learn "real" programming language(s).

Monday, April 02, 2007

Roman Numeral News

The Roman Numeral programs have since been finished, for a couple weeks now.
agilfoy AT frontiernet.net will get a couply for anyone who's interested. :)

Thanks Larry for the idea, it was incredible useful assignment for several reasons, but I doubyt I would have thought of it by myself.

After much frustration (as the work on the Roman Numeral program was the main impetus for the "On Programming Frustration" post), it's finally working for what I intend for it to do.

Finished project you say? Maybe not.
With this version completed, I have a program that:

freaks out when given improper inputs. (Not too worried about that, yet- I think the main idea of the assignment was to get the conversion logic right)

I have one thing in the program that tries to deal with improper inputs - I have one line of code in roman_to_decimal that converts roman_input to all uppercase. This screens out any inputs that have the letters in the right order, but lowercase. (My logic assumes that uppercase was entered)

Like that, I'm assuming that I'd handle potential errors on a case-by-case basis. This requires thinking, "How can my user mess up my program." :)

I have one idea to handle these errors that's totally "inline" - using roman_to_decimal() and decimal_result as an example (though this method still would work the other way around.) Here's some pseudocode:

#
if roman_input has thing X wrong with it:
decimal_result = "*X_error"

if roman_input has thing Y wrong with it:
decimal_result = "*Y_error"

if roman_input has thing Z wrong with it:
decimal_result = "*Z_error"
#

RomanNumeralConverter.py #the user interface program

if decimal_result[0] == "*": #asterisk only shows up when d_r has been set to an error message

print decimal_result #which is set to an error message. This line of code displays the error message to the user, without a built-in "exception" closing down the program.

if decimal_result[0] != "*": #This is what the program's already doing, when this function gets a proper input, it spits out a normally-formatted numerical answer.

print "The decimal equivalent of", roman_input, "is", decimal_result

0 Comments:

Post a Comment

<< Home