Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions lab Marco #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marcoayora
Copy link

No description provided.

@bripollc
Copy link

Marco:)

Nadie dijo que las funciones fueran fáciles 🙃 Buen lab! Aunque te dejo a continuación algunas correcciones:

  • Write another function that multiplies all the elements on a list
def mult_all(arr):
    total = 1  -- para la multiplicación debes iniciar el contador a 1
    for f in arr:
        total = total * f   -- tienes la línea mal identada
    return total

Con estas modificaciones debería pasarte el test:)

  • Now combine those two ideas and write a function that receives a list and either "+" or "*" and outputs acordingly
def oper_all(arr, oper):
    sum_of = 0
    mult = 1
    if oper == "+":
        for i in arr:
            sum_of += i
        return sum_of
    else:
        for i in arr:
            mult *= i
        return mult

En tu código pasan varias cosas. En primer lugar, tienes problemas de indentación en muchas líneas. Además, tienes un error en la acumulación de resultados tanto para la suma como para la multiplicación. Te dejo una de las maneras para resolver el ejercicio, así debería pasar el test!!!

  • Write a function that returns the factorial of a number.

La manera que calculas el factorial de un número es correcta, pero vuelves a tener problemas de identación en las líneas return 1 y result *= i. Ojo!! Además.. ¿porqué estás importando el módulo re? 🧐

  • Write a function that takes a list and returns a list of the unique values.

Te pasa el test, pero tienes el if mal identado 🙃

  • Write a function to check if a string is a pangram, i.e.: if it contains all the letters of the alphabet at least once. Mind that the strings may contain characters that are not letters.

Te pasa el test, pero tienes los dos print mal identados 🙃

  • Write a function to check if a given password is strong (at least 8 characters, at least one lower case, at least one upper case, at least one number and at least one special character). It should output True if strong and False if not.

Estas definiendo una función dentro de otra función con el mismo nombre 😵‍💫 Eliminando def check_pass(string):, debería funcionarte el código.

También te dejo algunas manera de resolver el bonus:

  • Write a function that returns the mode of a list, i.e.: the element that appears the most times.
def mode_counter(arr):
    counter = {} 

    for i in arr:
        if i in counter:
            counter[i] += 1  
        else:
            counter[i] = 1

    mode = max(counter, key=counter.get)

    return mode
  • Write a function that receives a string of comma separated words and returns a string of comma separated words sorted alphabetically.
def sort_alpha(string):
    word_list = string.split(", ") 
    word_list.sort()  
    sorted_string = ", ".join(word_list)
    return sorted_string
a_string = "call, you, later"
sort_alpha(a_string)

A por el siguiente lab!!! 💪🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants