Advertisement
GastonPalazzo

Var y Cond - Ej-12

Mar 31st, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. # funcion de conversion |num->alpha|
  2. def aAlfa(num):
  3.     num = int(num)
  4.     unidades=(
  5.     'cero',
  6.     'uno',
  7.     'dos',
  8.     'tres',
  9.     'cuatro',
  10.     'cinco',
  11.     'seis',
  12.     'siete',
  13.     'ocho',
  14.     'nueve'
  15.     )
  16.  
  17.     decenas=(
  18.     'dieci',
  19.     'veinti',
  20.     'treinti',
  21.     'cuarenti',
  22.     'cincuenti',
  23.     'sesenti',
  24.     'setenti',
  25.     'ochenti',
  26.     'noventi'
  27.     )
  28.  
  29.     excep=(
  30.     'once',
  31.     'doce',
  32.     'trece',
  33.     'catorce',
  34.     'quince'
  35.     )
  36.  
  37.     if num>-1 and num<100:
  38.         if num//10>0:
  39.             if num<16:
  40.                 #decenas < 16
  41.                 r = excep[(num%10)-1]
  42.             else:
  43.                 #decenas > 15
  44.                 r = decenas[(num//10)-1]+''+unidades[num%10]
  45.         else:
  46.             #unidades
  47.             r = unidades[num]
  48.     else:
  49.         r = 'Valor fuera de rango!'
  50.  
  51.     return r
  52.  
  53. # main
  54. cond = True
  55. print('|Conversor|')
  56. while cond==True:
  57.     opcion = input('\nOpciones\n\n1. Convertir\n0. Salir\n\n<opcion>: ')
  58.     if opcion == '0':
  59.         cond = False
  60.         print('\nFin de la ejecucion!\n')
  61.     elif opcion == '1':
  62.         r = aAlfa(input('\nIngrese numero entre 0 y 99: '))
  63.         print('\nRepresentacion alfabetica -> '+r)
  64.     else:
  65.         print('\nOpcion no valida!\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement