Advertisement
pmorriberon

Ejercicios Diccionarios

May 25th, 2019
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. #pregunta1
  4. def mayor(d):
  5.     return max(d.values())
  6.  
  7. #pregunta2
  8. def llena_diccionario():
  9.     clave = input()
  10.     val = input()
  11.     d = {}
  12.     while clave != "x":
  13.         d[clave] = val
  14.         clave = input()
  15.         val = input()
  16.     return d
  17.  
  18. #pregunta3
  19. def listas_diccionario(claves, valores):
  20.     d = {}
  21.     for i, j  in zip(claves, valores):
  22.         d[i] = j
  23.     return d
  24.  
  25. #pregunta4
  26. def mes_letras(n):
  27.     if n < 1 or n > 12:
  28.         return "Mes no valido"
  29.     d = {1: "Enero", 2: "Febrero", 3: "Marzo", 4: "Abril", \
  30.          5: "Mayo", 6: "Junio", 7: "Julio", 8: "Agosto", \
  31.          9: "Setiembre", 10: "Octubre", 11: "Noviembre", 12: "Diciembre"}
  32.     return d[n]
  33.  
  34. #pregunta5
  35. def mes_numero(mes):
  36.     if mes not in ["Enero", "Febrero", "Marzo", "Abril", \
  37.         "Mayo", "Junio", "Julio", "Agosto", \
  38.         "Setiembre", "Octubre", "Noviembre", "Diciembre"]:
  39.         return "Mes no valido"
  40.     d = {"Enero": 1, "Febrero": 2, "Marzo": 3, "Abril": 4, \
  41.          "Mayo": 5, "Junio": 6, "Julio": 7, "Agosto": 8, \
  42.          "Setiembre": 9, "Octubre": 10, "Noviembre": 11, "Diciembre": 12}
  43.     return d[mes]
  44.  
  45. #pregunta6
  46. def cuenta_palabras(text):
  47.     palabras = text.split(" ")
  48.     d = {}
  49.     for i in palabras:
  50.         if i in d.keys():
  51.             d[i] += 1
  52.         else:
  53.             d[i] = 1
  54.     return d
  55.  
  56. #pregunta7
  57. def cuenta_letras(text):
  58.     d = {}
  59.     for i in text:
  60.         if i in d.keys():
  61.             d[i] += 1
  62.         else:
  63.             d[i] = 1
  64.     return d
  65.  
  66. #test pregunta1
  67. #test = {1: 10, 2: 5, 3:8}
  68. #print(mayor(test))
  69.  
  70. #test pregunta2
  71. #print(llena_diccionario())
  72.  
  73. #test pregunta3
  74. #claves = [1, 2, 3, 4, 5]
  75. #valores  = ["Enero", "Febrero", "Marzo", "Abril", "Mayo"]
  76. #print(listas_diccionario(claves, valores))
  77.  
  78. #test pregunta4
  79. #print(mes_letras(8))
  80. #print(mes_letras(15))
  81.  
  82. #test pregunta5
  83. #print(mes_numero("x"))
  84. #print(mes_numero("Agosto"))
  85.  
  86. #test pregunta6
  87. #print(cuenta_palabras("si si si no juan pedro maria no si"))
  88.  
  89. #test pregunta7
  90. #print(cuenta_letras("si si si no juan pedro maria no si"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement