def to_OnlyNumbers(self): # Convertir este vector a uno con solo valores numericos # ------- Variables Locales ---------- motivo = "OK" condiciones = True # ----- Comprobar condiciones Inciales ------ if self.lengFix() <= 0: condiciones = False motivo = "Vector vacio" # ---------------- Proceso --------------- if condiciones == True: x = 0 while x < self.lengFix(): value = SNumbers.to_float_Force(self.vRaiz[x], None) if SNumbers.isNumber(value, True) == False: self.vRaiz.pop(x) x = x - 1 x = x + 1 else: # Mensaje de Error print("ERROR en to_OnlyNumbers motivo:" + motivo)
def to_Vector_OnlyNumbers(Svector): # Obtener un vector con solo valores numericos # ------- Variables Locales ---------- motivo = "OK" condiciones = True # ----- Comprobar condiciones Inciales ------ if Svector.lengFix() <= 0: condiciones = False motivo = "Vector vacio" # ---------------- Proceso --------------- if condiciones == True: salida = clone(Svector) x = 0 while x < salida.lengFix(): value = SNumbers.to_float_Force(salida.vRaiz[x], None) if SNumbers.isNumber(value, True) == False: salida.vRaiz.pop(x) x = x - 1 x = x + 1 return salida else: # Mensaje de Error print("ERROR en to_Vector_OnlyNumbers motivo:" + motivo)
def detele_Element_ALL_byCondition(vector, condicion, value): # Eliminar todos los elementos de un vector que cumplan una condicion # vector - Vector de Clase Shesha # condicion - ">,<,==,>=,<=" # value - Valor Derecho de la condicion # Return vector unicamente con elementos que si cumplen la condicion # Return vector vacio en caso de error # ------- Variables Locales ---------- motivo = "OK" condiciones = True salida = Vector() # ----- Comprobar condiciones Inciales ------ operadores = ">,<,==,>=,<=" if SStrings.numOfContains__Str_IN_Conjunt(condicion, operadores, ",") != 1: condiciones = False motivo = "Condicion no valida, condiciones validas: " + operadores # ---------------- Proceso --------------- if condiciones == True: salida = clone(vector) # Ver cuales elementos hay que eliminar for x in range(0, vector.lengFix()): dato = vector.getItem_index(x) # Si hay que comparar Strings if condicion == "==": if (dato == value): salida.deleteIndex(x) #Si hay que comparar datos numericos if SNumbers.isNumber(dato, False) and SNumbers.isNumber( value, False): if condicion == ">": if (dato > value): salida.deleteIndex(x) if condicion == "<": if (dato < value): salida.deleteIndex(x) if condicion == ">=": if (dato >= value): salida.deleteIndex(x) if condicion == "<=": if (dato <= value): salida.deleteIndex(x) return salida else: # Mensaje de Error print("ERROR en detele_Element_ALL_byCondition motivo:" + motivo) return salida
def calculatePoints(self): loc = [Numbers.rational(0, 1), Numbers.rational(0, 1)] self.rPoints = [[0, 0]] self.dPoints = [[0.0, 0.0]] for move in self.curve: loc[0].sum(Numbers.rational(move[0], self.size)) loc[1].sum(Numbers.rational(move[1], self.size)) self.rPoints.append(copy.deepcopy(loc)) self.dPoints.append([loc[0].getVal(), loc[1].getVal()]) return
def convertTime_Medida2Format(time, medida): # Convertir un Tiempo a un Formato # param time: Valor numerico Entero recibido # param medida: indicador de medida de time recibido, si es hh o mm o ss o ms # # # Return Formato hh:mm:ss:ms # Error return 00:00:00:0000 # ------- Variables Locales ---------- motivo = "OK" condiciones = True salida = "00:00:00:0000" medidas = "hh,mm,ss,ms" # ----- Comprobar condiciones Inciales ------ if SStrings.numOfContains__Conjunt_IN_Str(medidas, ",", medida) != 1: condiciones = False motivo = "Medida no valida, medidas validas: " + medidas # ---------------- Proceso --------------- if condiciones == True: # Convertir el tiempo en Microsegundos como unidad basica msT = convertTime_Medida2Medida(time, medida, "ms") # Obtener los tiempos hh = convertTime_Medida2Medida(msT, "ms", "hh") hh = SNumbers.to_Int(hh, 0) mm = convertTime_Medida2Medida( msT, "ms", "mm") - convertTime_Medida2Medida(hh, "hh", "mm") mm = SNumbers.to_Int(mm, 0) ss = convertTime_Medida2Medida( msT, "ms", "ss") - convertTime_Medida2Medida( hh, "hh", "ss") - convertTime_Medida2Medida(mm, "mm", "ss") ss = SNumbers.to_Int(ss, 0) ms = convertTime_Medida2Medida( msT, "ms", "ms") - convertTime_Medida2Medida( hh, "hh", "ms") - convertTime_Medida2Medida( mm, "mm", "ms") - convertTime_Medida2Medida( ss, "ss", "ms") ms = SNumbers.to_Int(ms, 0) # Convertir en formato de salida salida = SStrings.to_String(hh) salida = salida + ":" + SStrings.to_String( mm) + ":" + SStrings.to_String(ss) + ":" + SStrings.to_String(ms) return salida else: # Mensaje de Error print("ERROR en convertTime_Medida2Format motivo:" + motivo) return salida
def getSubVector_PosA_PosB(vector, posA, posB): # Obtener un subvector desde la posicionA hasta la posicionB # Error return VectorVacio # ------- Variables Locales ---------- motivo = "OK" condiciones = True salida = Vector() # ----- Comprobar condiciones Inciales ------ posA = SNumbers.to_Int(posA, -1) posB = SNumbers.to_Int(posB, -1) if posA == -1: condiciones = False motivo = "PosA no es un entero" if posB == -1: condiciones = False motivo = "PosB no es un entero" if condiciones == True: if vector.lengFix() <= 0: condiciones = False motivo = "Vector vacio" if (posA > vector.lengFix()) or (posA < 0): condiciones = False motivo = "PosA no valida" if (posB > vector.lengFix()) or (posB < 0): condiciones = False motivo = "PosB no valida" if posA > posB: condiciones = False motivo = "PosA > PosB" # ---------------- Proceso --------------- if condiciones == True: newVector = Vector() for x in range(posA, posB): newVector.addRigth(vector.getItem_index(x)) return newVector else: # Mensaje de Error print("ERROR en getSubVector_PosA_PosB motivo:" + motivo) return salida
def getModaDiferencial(self, error, Diferencial): # Obtener la moda diferencial del vector # ------- Variables Locales ---------- motivo = "OK" condiciones = True salida = error # ----- Comprobar condiciones Inciales ------ if self.lengFix() <= 0: condiciones = False motivo = "Vector vacio" # ---------------- Proceso --------------- if condiciones == True: # Bandera de la moda, inicialmente el elemento 1 pos = 0 countModa = 0 #Para cada elemento comprobar sus repeticiones countActual = 0 for x in range(0, self.lengFix()): elementActual = SNumbers.to_float(self.vRaiz[x], 0) min = elementActual - Diferencial max = elementActual + Diferencial #Contar las repeticiones del elemento actual for y in range(0, self.lengFix()): if y == x: # Si es el mismo elemento, no contarlo 2 veces pass else: # Obtener el elemento a contabilizar value = SNumbers.to_float(self.vRaiz[y], 0) # Si el elemento esta en el rango if SNumbers.inRange(min, value, max): countActual = countActual + 1 # Finalmente comprobar si el elemento actual es la nueva moda if countActual > countModa: pos = x countModa = countActual # Finalmente entregar la moda return self.vRaiz[pos] else: # Mensaje de Error print("ERROR en getPromedio motivo:" + motivo) return salida
def gettranslation(self, word): """Translates a single galbraithanese word into english.""" try: return str(Numbers.from_galbraithanese(word)) except: pass if word in ["óstīðōyó", "ᵲōsnôfôbr", "lēvēy", "jūkwôbr"]: return "love" elif word in ["óstīðōyóēnē", "ᵲōsnôfôbrēnē", "lēvēyēnē", "jūkwôbrēnē"]: return "loved" elif word in ["óstīðōyóîgē", "ᵲōsnôfôbrîgē", "lēvēyîgē", "jūkwôbrîgē"]: return "loving" else: for eng in self.dictionary: if self.dictionary[eng]==word: return eng elif self.dictionary[eng]==word[:-5] and word[-5:]=="ēnē": if eng[-1]=="e": return eng+"d" return eng+"ed" elif self.dictionary[eng]==word[:-5] and word[-5:]=="îgē": if eng[-1]=="e": return eng[:-1]+"ing" return eng+"ing" elif self.dictionary[eng]==word[:-4] and word[-4:]=="əʃ": if eng[-1]=="y": return eng[:-1]+"ily" return eng+"ly" elif self.dictionary[eng]==word[:-5] and word[-5:]=="glôb": if eng[-1]=="s": return eng[:-1]+"es" return eng+"s" return "?"*len(word)
def getword(self, word): """Translates one word into Galbraithanese.""" if all(map(lambda x: x.isdigit(), list(word))) and word: return Numbers.galbraithanese_number(int(word)) elif set(list(word))==set(['\x98', '\x83', '\xe2']): return word elif word=="love": return random.choice(["óstīðōyó", "ᵲōsnôfôbr", "lēvēy", "jūkwôbr"]) elif word=="loved": return random.choice(["óstīðōyóēnē", "ᵲōsnôfôbrēnē", "lēvēyēnē", "jūkwôbrēnē"]) elif word=="loving": return random.choice(["óstīðōyóîgē", "ᵲōsnôfôbrîgē", "lēvēyîgē", "jūkwôbrîgē"]) elif word in self.dictionary: return self.dictionary[word] elif word[:-2] in self.dictionary and word[-2:]=="ly": return self.dictionary[word[:-2]]+"əʃ" elif word[:-3]+"y" in self.dictionary and word[-2:]=="ily": return self.dictionary[word[:-3]+y]+"əʃ" elif word[:-3] in self.dictionary and word[-3:]=="ing": return self.dictionary[word[:-3]]+"îgē" elif word[:-3]+"e" in self.dictionary and word[-3:]=="ing": return self.dictionary[word[:-3]+"e"]+"îgē" elif word[:-2] in self.dictionary and word[-2:]=="ed": return self.dictionary[word[:-2]]+"ēnē" elif word[:-1] in self.dictionary and word[-1]=="d": return self.dictionary[word[:-1]]+"ēnē" elif word[:-1] in self.dictionary and word[-1]=="s": return self.dictionary[word[:-1]]+"glôb" elif word[:-2] in self.dictionary and word[-2:]=="es": return self.dictionary[word[:-2]]+"glôb" else: return "?"*len(word)
def is_OnlyNumbers(self): # Comprobar si este vector contiene elementos solo Numericos # ------- Variables Locales ---------- motivo = "OK" condiciones = True # ----- Comprobar condiciones Inciales ------ if self.lengFix() <= 0: condiciones = False motivo = "Vector vacio" # ---------------- Proceso --------------- if condiciones == True: correct = True x = 0 while x < self.lengFix(): if SNumbers.isNumber(self.vRaiz[x], True) == False: correct = False x = self.lengFix() x = x + 1 return correct else: # Mensaje de Error print("ERROR en is_OnlyNumbers motivo:" + motivo) return False
def Add(self): InstanceHandle = ctypes.c_void_p() self._wrapper.checkError(self, self._wrapper.lib.calculation_calculator_add(self._handle, InstanceHandle)) if InstanceHandle: InstanceObject = Numbers.Variable(InstanceHandle, self._wrapper._NumbersWrapper) else: raise ECalculationException(ErrorCodes.INVALIDCAST, 'Invalid return/output value') return InstanceObject
def valideTimeFormat(timeFormat): # Validar si una fecha cumple con el formato hh:mm:ss:ms # hh formato de 24 horas # Formato hh:mm:ss:ms # ------- Variables Locales ---------- motivo = "OK" condiciones = True salida = True # ----- Comprobar condiciones Inciales ------ # ---------------- Proceso --------------- if condiciones == True: v = SStrings.toVector(timeFormat, ":") # Comprobar que existan la cantidad de elementos requeridos if SVector.lengFix(v) != 4: salida = False else: # Comprobar que todos los elementos sean numericos for x in range(0, len(v)): if SNumbers.isNumber(v[x], True) == False: salida = False # Comprobar el rango de los Numeros if x == 0: if SNumbers.inRange(0, v[x], 24) == False: salida = False if (x == 1) or (x == 2): if SNumbers.inRange(0, v[x], 60) == False: salida = False if (x == 3): if SNumbers.to_float_Force(v[x], 0) < 0: salida = False return salida else: # Mensaje de Error print("ERROR en valideTimeFormat motivo:" + motivo) return salida
def GetEnlistedVariable(self, Index): nIndex = ctypes.c_uint32(Index) VariableHandle = ctypes.c_void_p() self._wrapper.checkError(self, self._wrapper.lib.calculation_calculator_getenlistedvariable(self._handle, nIndex, VariableHandle)) if VariableHandle: VariableObject = Numbers.Variable(VariableHandle, self._wrapper._NumbersWrapper) else: raise ECalculationException(ErrorCodes.INVALIDCAST, 'Invalid return/output value') return VariableObject
def translate(tokens, translation=None): translations = [] inferred_meanings = None if translation is not None: inferred_meanings = Infer.infer(tokens, translation) i = -1 for token in tokens: i += 1 jp = token.word last = i == len(tokens) - 1 if not last: if is_sentence_ending_symbol(tokens[i + 1].word): last = True if is_ending(token): translation = translate_ending(token) translations.append(Translation(token, translation)) continue translation = match_special(jp, last) if translation: translations.append(Translation(token, translation)) continue if inferred_meanings is not None: translation = inferred_meanings[i] if translation is not None: translations.append(Translation(token, translation)) continue translation = get_translation_from_dictionary(token) if translation: translations.append(Translation(token, translation)) continue if is_katakana(jp): translations.append(Translation(token, Katakana.translate(jp))) continue if is_english(jp): translations.append(Translation(token, jp)) continue if is_number(jp): translations.append(Translation(token, Numbers.convert(jp))) continue translations.append(Translation(token, token.word)) return translations
def InjectComponent(self, NameSpace, SymbolAddressMethod): pNameSpace = ctypes.c_char_p(str.encode(NameSpace)) pSymbolAddressMethod = ctypes.c_void_p(SymbolAddressMethod) self.checkError(None, self.lib.calculation_injectcomponent(pNameSpace, pSymbolAddressMethod)) bNameSpaceFound = False if NameSpace == "Numbers": if self._NumbersWrapper is not None: raise ECalculationException(ErrorCodes.COULDNOTLOADLIBRARY, "Library with namespace " + NameSpace + " is already registered.") self._NumbersWrapper = Numbers.Wrapper(symbolLookupMethodAddress = SymbolAddressMethod) bNameSpaceFound = True if not bNameSpaceFound: raise ECalculationException(ErrorCodes.COULDNOTLOADLIBRARY, "Unknown namespace " + NameSpace)
def to_Vector_Dx(Svector): # Obtener un vector Diferencial # Cada elemento es el resultado de la diferencia del valores siguiente menos el anterior # En caso de error Resultado: Vector con elementos vacios # ------- Variables Locales ---------- motivo = "OK" condiciones = True salida = Vector() # ----- Comprobar condiciones Inciales ------ if Svector.lengFix() <= 0: condiciones = False motivo = "Vector vacio" if Svector.is_OnlyNumbers() == False: condiciones = False motivo = "Vector Con Elementos No Numericos" # ---------------- Proceso --------------- if condiciones == True: salida = Vector() for x in range(0, Svector.lengFix() - 1): valNext = Svector.vRaiz[x + 1] valNext = SNumbers.to_float(valNext, 0) valBefore = Svector.vRaiz[x] valBefore = SNumbers.to_float(valBefore, 0) Dx = valNext - valBefore salida.addRigth(Dx) return salida else: # Mensaje de Error print("ERROR en to_Vector_Dx motivo:" + motivo) return salida
def test(): fs = FacetedSearch() num = Numbers() srt = Sorting() prb = Probability() print("Тест первого задания: ") fs.start_search() print("----------------------") print("Тест второго задания: ") num.perform_distribution() print("----------------------") print("Тест третьего задания: ") srt.fill_array() print("Пузырьковая сортировка:") srt.bubble_sort() print("Гномья сортировка:") srt.gnome_sort() print("Блочная сортировка:") srt.bucket_sort() print("Пирамидальная сортировка:") srt.pyramid_sort() print("----------------------") print("Тест четвертого задания: ") prb.count_probability()
def __init__(self, handle): super(PeterActivity, self).__init__(handle) # Build the activity toolbar. toolbox = activity.ActivityToolbox(self) activity_toolbar = toolbox.get_activity_toolbar() activity_toolbar.keep.props.visible = False activity_toolbar.share.props.visible = False toolbox.show() self.set_toolbox(toolbox) # Create the game instance. self.game = Numbers.Numbers() # Build the Pygame canvas. self._pygamecanvas = \ sugargame.canvas.PygameCanvas(self) # Note that set_canvas implicitly calls # read_file when resuming from the Journal. self.set_canvas(self._pygamecanvas) # Start the game running. self._pygamecanvas.run_pygame(self.game.run)
import Numbers Numbers.add()
def cargar_config(self): # Mostrar la informacion de uso de este robot # ------- Variables Locales ---------- motivo = "OK" condiciones = True salida = None # ----- Comprobar condiciones Inciales ------ # ---------------- Proceso --------------- if condiciones == True: file = SFiles.Text(self.pathFileConfig) posCoordenades = file.posLineLike("#Coordenadas(Start)#", "#") # Obtener datos Paso1: Abrir Navegador Web line = file.getLine(posCoordenades + 1) self.Step1_alto = SStrings.getSubStr_StrA_StrB(line, "alto(", ")") self.Step1_alto = SNumbers.to_Int_Force(self.Step1_alto, 0, "CLOSE") self.Step1_ancho = SStrings.getSubStr_StrA_StrB( line, "ancho(", ")") self.Step1_ancho = SNumbers.to_Int_Force(self.Step1_ancho, 0, "CLOSE") self.Step1_time = SStrings.getSubStr_StrA_StrB(line, "time(", ")") self.Step1_time = SNumbers.to_Int_Force(self.Step1_time, 0, "CLOSE") # Obtener datos Paso1: Abrir pestaña del navegador line = file.getLine(posCoordenades + 2) self.Step2_alto = SStrings.getSubStr_StrA_StrB(line, "alto(", ")") self.Step2_alto = SNumbers.to_Int_Force(self.Step2_alto, 0, "CLOSE") self.Step2_ancho = SStrings.getSubStr_StrA_StrB( line, "ancho(", ")") self.Step2_ancho = SNumbers.to_Int_Force(self.Step2_ancho, 0, "CLOSE") self.Step2_time = SStrings.getSubStr_StrA_StrB(line, "time(", ")") self.Step2_time = SNumbers.to_Int_Force(self.Step2_time, 0, "CLOSE") # Obtener datos Paso1: Buscar persona o grupo line = file.getLine(posCoordenades + 3) self.Step3_alto = SStrings.getSubStr_StrA_StrB(line, "alto(", ")") self.Step3_alto = SNumbers.to_Int_Force(self.Step3_alto, 0, "CLOSE") self.Step3_ancho = SStrings.getSubStr_StrA_StrB( line, "ancho(", ")") self.Step3_ancho = SNumbers.to_Int_Force(self.Step3_ancho, 0, "CLOSE") self.Step3_time = SStrings.getSubStr_StrA_StrB(line, "time(", ")") self.Step3_time = SNumbers.to_Int_Force(self.Step3_time, 0, "CLOSE") # Obtener datos Paso1: Escribir en cuadro de chat line = file.getLine(posCoordenades + 4) self.Step4_alto = SStrings.getSubStr_StrA_StrB(line, "alto(", ")") self.Step4_alto = SNumbers.to_Int_Force(self.Step4_alto, 0, "CLOSE") self.Step4_ancho = SStrings.getSubStr_StrA_StrB( line, "ancho(", ")") self.Step4_ancho = SNumbers.to_Int_Force(self.Step4_ancho, 0, "CLOSE") self.Step4_time = SStrings.getSubStr_StrA_StrB(line, "time(", ")") self.Step4_time = SNumbers.to_Int_Force(self.Step4_time, 0, "CLOSE") # Obtener datos Paso1: Darle al boton Enviar line = file.getLine(posCoordenades + 5) self.Step5_alto = SStrings.getSubStr_StrA_StrB(line, "alto(", ")") self.Step5_alto = SNumbers.to_Int_Force(self.Step5_alto, 0, "CLOSE") self.Step5_ancho = SStrings.getSubStr_StrA_StrB( line, "ancho(", ")") self.Step5_ancho = SNumbers.to_Int_Force(self.Step5_ancho, 0, "CLOSE") self.Step5_time = SStrings.getSubStr_StrA_StrB(line, "time(", ")") self.Step5_time = SNumbers.to_Int_Force(self.Step5_time, 0, "CLOSE") # Obtener datos Paso1: Darle al boton AddArchivo line = file.getLine(posCoordenades + 6) self.Step6_alto = SStrings.getSubStr_StrA_StrB(line, "alto(", ")") self.Step6_alto = SNumbers.to_Int_Force(self.Step6_alto, 0, "CLOSE") self.Step6_ancho = SStrings.getSubStr_StrA_StrB( line, "ancho(", ")") self.Step6_ancho = SNumbers.to_Int_Force(self.Step6_ancho, 0, "CLOSE") self.Step6_time = SStrings.getSubStr_StrA_StrB(line, "time(", ")") self.Step6_time = SNumbers.to_Int_Force(self.Step6_time, 0, "CLOSE") else: # Mensaje de Error print("ERROR en cargar_config motivo:" + motivo) return salida
def convertTime_Format2Medida(time, medida): # Convertir un Tiempo a una mediad en horas, minutos, segundos, microsegundos # time: valor en formato hh:mm:ss:ms # medida: medida de salida del tiempo # # # Return 0 en Error, Exito return N entero # ------- Variables Locales ---------- motivo = "OK" condiciones = True salida = 0 medidas = "hh,mm,ss,ms" # ----- Comprobar condiciones Inciales ------ if valideTimeFormat(time) == False: condiciones = False motivo = "time no valido en formato: hh:mm:ss:ms" if SStrings.numOfContains__Conjunt_IN_Str(medidas, ",", medida) != 1: condiciones = False motivo = "Medida no valida, medidas validas: " + medidas # ---------------- Proceso --------------- if condiciones == True: # Separar tiempo en sus medidas v = SStrings.toVector(time, ":") hora = v[0] mins = v[1] segs = v[2] micr = v[3] # Convertir a numeros hora = SNumbers.to_Int(hora, 0) mins = SNumbers.to_Int(mins, 0) segs = SNumbers.to_Int(segs, 0) micr = SNumbers.to_Int(micr, 0) # Calcular todo a la unidad de medida dada if medida == "hh": salida = SNumbers.to_float(hora, 0) salida = salida + (mins / 60) salida = salida + (segs / 3600) salida = salida + (micr / 3600000000) if medida == "mm": salida = SNumbers.to_float(mins, 0) salida = salida + (hora * 60) salida = salida + (segs / 60) salida = salida + (micr / 60000000) if medida == "ss": salida = SNumbers.to_float(segs, 0) salida = salida + (hora * 3600) salida = salida + (mins * 60) salida = salida + (micr / 1000000) if medida == "ms": salida = SNumbers.to_Int(micr, 0) salida = salida + (hora * 60 * 60 * 1000000) salida = salida + (mins * 60 * 1000000) salida = salida + (segs * 1000000) return salida else: # Mensaje de Error print("ERROR en convertTime_Format2Medida motivo:" + motivo) return salida
def convertTime_Medida2Medida(time, medidaIN, medidaOUT): # Convertir tiempo de un formato a otro # time valor Entero numerico del tiempo # formatIN formato de entrada: nanosegundos, milisegundos, segundos, minutos, horas, dias # formatOUT formato de salida: nanosegundos, milisegundos, segundos, minutos, horas, dias # EXITO return valorEntero en formato hh,mm,ss,ms # ERROR return 0 # ------- Variables Locales ---------- motivo = "OK" condiciones = True salida = 0 formatos = "hh,mm,ss,ms" # ----- Comprobar condiciones Inciales ------ if SStrings.numOfContains__Conjunt_IN_Str(formatos, ",", medidaIN) != 1: condiciones = False motivo = "Formato de entrada no reconocido, formatos valido: " + formatos if SStrings.numOfContains__Conjunt_IN_Str(formatos, ",", medidaOUT) != 1: condiciones = False motivo = "Formato de salida no reconocido, formatos valido: " + formatos # ---------------- Proceso --------------- if condiciones == True: # Convertir el formato de entrada a microsegundos msIN = SNumbers.to_Int_Force(time, 0, "DOWN") if medidaIN == "ms": # Formato actual pass if medidaIN == "ss": msIN = time * 1000000 if medidaIN == "mm": msIN = time * 1000000 * 60 if medidaIN == "hh": msIN = time * 1000000 * 60 * 60 # Convertir los msIN en el formato de salida if medidaOUT == "ms": # Formato actual pass if medidaOUT == "ss": msIN = msIN / 1000000 if medidaOUT == "mm": msIN = msIN / 1000000 msIN = msIN / 60 if medidaOUT == "hh": msIN = msIN / 1000000 msIN = msIN / 60 msIN = msIN / 60 return msIN else: # Mensaje de Error print("ERROR en convert_Time motivo:" + motivo) return salida
def __init__(self, handle): super(PeterActivity, self).__init__(handle) # Get user's Sugar colors sugarcolors = profile.get_color().to_string().split(',') colors = [[ int(sugarcolors[0][1:3], 16), int(sugarcolors[0][3:5], 16), int(sugarcolors[0][5:7], 16) ], [ int(sugarcolors[1][1:3], 16), int(sugarcolors[1][3:5], 16), int(sugarcolors[1][5:7], 16) ]] # No sharing self.max_participants = 1 # Build the activity toolbar. toolbox = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbox.toolbar.insert(activity_button, 0) activity_button.show() self._add_level_slider(toolbox.toolbar) green = ToolButton('green') toolbox.toolbar.insert(green, -1) green.set_tooltip(_('Run')) green.connect('clicked', self._button_cb, 'green') green.show() separator = Gtk.SeparatorToolItem() separator.props.draw = True toolbox.toolbar.insert(separator, -1) separator.show() label = Gtk.Label('') label.set_use_markup(True) label.show() labelitem = Gtk.ToolItem() labelitem.add(label) toolbox.toolbar.insert(labelitem, -1) labelitem.show() separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbox.toolbar.insert(separator, -1) separator.show() stop = StopButton(self) toolbox.toolbar.insert(stop, -1) stop.show() toolbox.show() self.set_toolbar_box(toolbox) # Create the game instance. self.game = Numbers.Numbers(colors, sugar=True) # Build the Pygame canvas. self._pygamecanvas = sugargame.canvas.PygameCanvas(self) # Note that set_canvas implicitly calls # read_file when resuming from the Journal. self.set_canvas(self._pygamecanvas) self.game.canvas = self._pygamecanvas self.game.set_buttons(green) self.game.set_label(label) Gdk.Screen.get_default().connect('size-changed', self.__configure_cb) # Start the game running. self._pygamecanvas.run_pygame(self.game.run)
def sum(): Numbers.numbers() print(n1 + n2)
def test(self): num1 = 5 num2 = 10 total = 15 res = Numbers.num().add(num1, num2) self.assertEqual(total, res)
def dividetest(self): num1 = 10 num2 = 2 total = 5 res = Numbers.num().divide(num1, num2) self.assertEqual(total, res)
def test_number_4(self): number = "90億" english = Numbers.convert(number) self.assertEqual("9 billion", english)
def test_number_3(self): number = "二〇〇" english = Numbers.convert(number) self.assertEqual("200", english)
def test_number_2(self): number = "三一一" english = Numbers.convert(number) self.assertEqual("311", english)
def test_number_1(self): number = "12383万" english = Numbers.convert(number) self.assertEqual("123.83 million", english)
def AdjustSize(cad, dir, symbol, size): # Ajustar una cadena a cierta Longitud, rellenando de simbolo en direccion Izq o Der # dir -> "L" "R" # ------- Variables Locales ---------- motivo = "OK" condiciones = True salida = "" tamOriginal = 0 diferencia = 0 # ----- Comprobar condiciones Inciales ------ if (lengFix(symbol) < 1): condiciones = False motivo = "Simbolo de longitud CERO" if (size < 0): condiciones = False motivo = "Valor de Longitud Negativo" if (cad == None): condiciones = False motivo = "Cadena Null" if ((dir == "L") or (dir == "R")) == False: condiciones = False motivo = "Direccion no soportada, usa: L o R" # ---------------- Proceso --------------- if condiciones == True: # Calcular la diferencia salida = cad tamOriginal = lengFix(cad) diferencia = size - tamOriginal # Aumentar if (diferencia >= 0): # Generar la Cadena a concatenar cadAux = "" numConcat = SNumbers.roundInteger(diferencia / lengFix(symbol), "UP") for i in range(0, numConcat): cadAux = cadAux + symbol cadAux = getSubStr_PosA_Size(cadAux, 0, diferencia) # Concatenar a la Cadena Original if dir == "L": salida = cadAux + salida #Izquierda else: salida = salida + cadAux #Derecha else: # Disminuir la cadena if dir == "L": salida = getSubStr_posA_posB(salida, (-diferencia), len(salida)) #Izquierda else: salida = getSubStr_posA_posB( salida, 0, (tamOriginal + diferencia)) #Derecha return salida else: # Mensaje de Error print("ERROR en AdjustSize motivo:" + motivo) return salida