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

trabajo aida jueves #17

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

Conversation

aidagarcd
Copy link

daida garcia trabajo jueves

@bripollc
Copy link

Aida:)

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

  • Write a function that returns the greater of two numbers:
def greater(a,b):
    if a > b:
        return a
    else:
        return b

Tu código pasa el test pero ojo! Declaras dos if statement. No es necesario verificar si b es mayor que a después de comprobar si a es mayor que b. Sería más eficiente utilizar el else.

  • Now combine those two ideas and write a function that receives a list and either "+" or "*" and outputs acordingly
    def oper_all(arr, oper):
def oper_all(arr, oper):
    result = 0   -- debes inicializar en 0 para la suma
    if oper == "+":
        for i in arr:
            result += i
        return result  -- debes identarlo correctamente
    elif oper == "*":
        result = 1   -- ¡ debes inicializar en 1 para la multiplicación
        for i in arr:
            result *= i    --  debes usar *= para la multiplicación
        return result   --  debes identarlo correctamente 

Con estas correcciones debería pasarte el test.

  • Write a function that takes a list and returns a list of the unique values.
def unique(lst):
    unique_list = []

    for item in lst:
        if item not in unique_list:
            unique_list.append(item)

    return unique_list

Estas pasando arr como parámetro en la función, pero en el bucle for estás tratando de iterar sobre l. Te recomiendo que utilices lst en lugar de l para las listas ya que te facilitará la lectura del código en un futuro.

  • 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.
 def pangram(string):
    alpha="abcdefghijklmnopqrstuvwxyz"
    for i in alpha:
        if i not in string.lower():
            return False
    return True
  • 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.
def check_pass(string):

    special_chars = ['#', '@', '!', '$', '%', '&', '(', ')', '^', '*', '[', ']', '{', '}']
    
    lowercase = False
    uppercase = False
    number = False
    special = False
    
    if len(string) < 8:
        return False
    
    for i in string:
        if i.islower():
            lowercase = True
        
        if i.isupper():
            uppercase = True
        
        if i.isdigit():
            number = True
        
        if i in special_chars:
            special = True
        
        if lowercase and uppercase and number and special:
            return True
    
    return False

Te dejo también algunas maneras 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