Misión 1. Paso a paso:
- Ya habíamos creado un procedimiento para reducir el programa de saludos
def saludos(nombrePersona):
saludar = “Hola ,” + nombrePersona + “, ¿Cómo estás?”
print(saludar)
- Si queremos probar cómo funciona, solo escribimos el nombre de la función y pasamos por parámetro el nombre de la persona que vamos a saludar.
saludos(“Ly”)
saludos(“Lucía”)
saludos(“Julián”)
Nota: Prueba con otros nombres y no olvides las comillas dobles cuando llames al procedimiento saludos.
Misión 2. Paso a paso:
Veamos ahora un procedimiento que usa más de un parámetro.
- En el siguiente código, el procedimiento reporteNotas acepta dos parámetros, y los utiliza para reportar la puntuación de un estudiante en un examen de 30 preguntas:
def reporteNotas(nombreEstudiante, numCorrectas):
puntos = (numCorrectas/30) * 100
reporte = nombreEstudiante + ” obtuvo: ” + str(puntos)
print(reporte)
reporteNotas (“Mary”, 25)
reporteNotas (“Oliver”, 29)
- Pasamos como parámetros una cadena y un número.
Misión 3. Paso a paso:
- Para finalizar, el siguiente procedimiento recibe variables como parámetros. Este programa muestra el resultado de la multiplicación de dos números.
def mostrarmultip(num1, num2):
multiplicar = num1 * num2
print(str(num1) + ” x ” + str(num2) + ” = ” + str(multiplicar))
- Y recibe como parámetro el valor de una variable.
primerNum = 9
mostrarmultip(primerNum, 1)
mostrarmultip(primerNum, 2)
mostrarmultip(primerNum, 3)
- Prueba cambiar el valor de la variable primerNum y ver los resultados de la llamada a ese procedimiento.
Cuando estés listo, da clic en continuar.