Feb. 5th – 2009 Pyowa Meeting Wrap-up

At our Pyowa meeting last night, we had 7 new people plus myself. I thought it was a good turnout considering 5 people dropped out over the past few days. We spoke a little about having a Python Day of our own, but we didn’t really come up with much. Thus, I am asking for ideas and hope to get them compiled for our next meeting so we can set a date.

The rest of the meeting was spent working on the first couple of goofy computer problems I had. We had three teams working on them, and we had quite a variety. I went with functions and another went completely OOP with a class interface. We were just converting Celsius to Fahrenheit and vice-versa. The 2nd program was to take a series of numbers and change them to text, for example:

If the user enters: 123, then the output should be “one two three”. To make things tougher, we also needed a way to do negative numbers. Here’s one way to do it:

[python]
numberDict = {0:"zero", 1:"one", 2:"two", 3:"three", 4:"four",
5:"five", 6:"six", 7:"seven", 8:"eight", 9:"nine"}

value = raw_input("Please enter a number or series of numbers to be converted to text: ")

for val in value:
if isinstance(val, str) and val == "-":
print "minus",
else:
try:
# Only print characters that can be converted to the integer type
print numberDict[int(val)],
except:
pass

Of course, there are many problems with this implementation. For example, there’s not much in the way of exception handling and there’s no way to run it again without just re-running the script. It would be better as a function or a class, but I’ll leave those tasks as an exercise for the reader.

Our next meeting will be March 2nd, 2009 at the Marshall County Sheriff’s Office. I hope to see you there!