teslariu

for y mas

Jul 1st, 2023
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. '''
  5. Ejemplo básico del uso del for
  6. lista = ["Juan", "Pepe", "Ana", "Sofia"]
  7.  
  8. for nombre in lista:
  9. print(nombre)
  10.  
  11. Ejercicios:
  12. 1) Pedir una frase y contar cuantas vocales tiene (DIFICIL)
  13. 2) Modificar el programa de notas para contar cuantos aplazos hay (nota de 0 a 3)
  14. (DIFICIL)
  15. 3) Imprimir una lista en forma invertida (FACIL)
  16. 4) Generar dos listas y formar una lista con los valores intercalados
  17. ej impares=[1,3,5] pares =[2,4,6] --> generar [1,2,3,4,5,6]
  18.  
  19. # ejercicio 1
  20. total_vocales = 0
  21. frase = input("Ingrese la frase: ")
  22.  
  23. for caracter in frase:
  24. if caracter.lower() in "aeiou":
  25. total_vocales = total_vocales + 1
  26.  
  27. print(f"Total de vocales: {total_vocales}")
  28.  
  29. # 2) Ingresar notas de alumnos. La carga de notas finalizará con nota = -1
  30. # Al finalizar, mostrar el promedio, la nota mas alta, la más baja
  31. # la cantidad de notas y el total de aplazos (notas 0,1,2 o 3)
  32. from tabulate import tabulate
  33. tabla = []
  34.  
  35.  
  36. notas = []
  37. aplazos = 0
  38.  
  39. while True:
  40. nota = int(input("Ingrese una nota: "))
  41.  
  42. if nota == -1:
  43. break
  44.  
  45. elif 0 <= nota <= 10:
  46. notas.append(nota)
  47. if 0 <= nota <= 3:
  48. aplazos = aplazos + 1
  49.  
  50. else:
  51. print("Error en el ingreso de la nota")
  52.  
  53. tabla.append(["Total de notas", len(notas)])
  54. tabla.append(["Promedio", f"{sum(notas) / len(notas):.2f}"])
  55. tabla.append(["Nota máxima", max(notas)])
  56. tabla.append(["Nota mínima", min(notas)])
  57. tabla.append(["Total de aplazos", aplazos])
  58.  
  59.  
  60. print(tabulate(
  61. tabla,
  62. tablefmt="psql",
  63. colalign=["left", "center"]
  64. )
  65. )
  66.  
  67. print(f"""
  68. Total de notas: {len(notas)}
  69. Promedio: {sum(notas) / len(notas):.2f}
  70. Nota máxima: {max(notas)}
  71. Nota mínima: {min(notas)}
  72. Total de aplazos: {aplazos}
  73. """)
  74. '''
  75. # script que imprime el cuadrado y el cubo de los nros del 1 al 1000
  76.  
  77. # funcion range() crea colecciones en forma dinámica
  78. # range(tope) range(10) --> [0,1,2,3,4,5,6,7,8,9]
  79. # range(inicio, tope) range(2,7) --> [2,3,4,5,6]
  80. # range(inicio, tope, incremento) range(14,8,-3) --> [14, 11]
  81.  
  82. for i in range(1,1001):
  83. print(i, i**2, i**3, sep="\t")
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
Advertisement
Add Comment
Please, Sign In to add comment