Update of /cvsroot/pythoncard/PythonCard/samples/conversions
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16791
Modified Files:
conversions.py
Log Message:
added numbers and changed conversion algorithm for morse code
Index: conversions.py
===================================================================
RCS file: /cvsroot/pythoncard/PythonCard/samples/conversions/conversions.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** conversions.py 28 Mar 2005 05:49:14 -0000 1.15
--- conversions.py 14 Nov 2005 22:33:13 -0000 1.16
***************
*** 45,58 ****
class MorseCodeConversion(Conversion):
def __init__(self, components):
! """
! A B C D E F G
! H I J K L M N
! O P Q R S T U
! V W X Y Z
! """
self.morseAlphabet = ['.-', '-...', '-.-.', '-..', '.', '..-.', '--.',
'....', '..', '.---', '-.-', '.-..', '--', '-.',
'---', '.--.', '--.-', '.-.', '...', '-', '..-',
! '...-', '.--', '-..-', '-.--', '--..']
components.labelUp.text = 'English'
--- 45,60 ----
class MorseCodeConversion(Conversion):
def __init__(self, components):
! self.alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G',
! 'H', 'I', 'J', 'K', 'L', 'M', 'N',
! 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
! 'V', 'W', 'X', 'Y', 'Z', '0', '1',
! '2', '3', '4', '5', '6', '7', '8',
! '9']
self.morseAlphabet = ['.-', '-...', '-.-.', '-..', '.', '..-.', '--.',
'....', '..', '.---', '-.-', '.-..', '--', '-.',
'---', '.--.', '--.-', '.-.', '...', '-', '..-',
! '...-', '.--', '-..-', '-.--', '--..',
! '-----', '.----', '..---', '...--', '....-', '.....',
! '-....', '--...', '---..', '----.']
components.labelUp.text = 'English'
***************
*** 68,88 ****
def convertToMorse(self, txt):
- a = ord('A')
- z = ord('Z')
converted = ''
for c in txt[:]:
! ordC = ord(c.upper())
if c == ' ':
# three spaces between words
# when you include the space after each character
converted = converted + ' '
- elif ordC < a or ordC > z:
- return converted + "\n\ncharacter out of bounds, unable to complete conversion"
else:
! converted += self.morseAlphabet[ordC - a] + ' '
return converted[:-1]
def convertFromMorse(self, txt):
- a = ord('A')
converted = ''
words = txt.split(' ')
--- 70,88 ----
def convertToMorse(self, txt):
converted = ''
for c in txt[:]:
! ordC = c.upper()
if c == ' ':
# three spaces between words
# when you include the space after each character
converted = converted + ' '
else:
! try:
! converted += self.morseAlphabet[self.alphabet.index(ordC)] + ' '
! except:
! return converted + "\n\ncharacter out of bounds, unable to complete conversion"
return converted[:-1]
def convertFromMorse(self, txt):
converted = ''
words = txt.split(' ')
***************
*** 93,100 ****
continue
try:
! ordC = self.morseAlphabet.index(c)
except:
return converted + "\n\nmorse out of bounds error, unable to complete conversion"
! converted += chr(ordC + a)
converted += ' '
return converted
--- 93,100 ----
continue
try:
! ordC = self.alphabet[self.morseAlphabet.index(c)]
except:
return converted + "\n\nmorse out of bounds error, unable to complete conversion"
! converted += ordC
converted += ' '
return converted
|