Skip to content

Lab_Functions_Martina_Rivero#10

Open
Futurartina wants to merge 1 commit intoIronhack-data-bcn-oct-2023:mainfrom
Futurartina:main
Open

Lab_Functions_Martina_Rivero#10
Futurartina wants to merge 1 commit intoIronhack-data-bcn-oct-2023:mainfrom
Futurartina:main

Conversation

@Futurartina
Copy link
Copy Markdown

Help me with exercise 10!

@bripollc
Copy link
Copy Markdown

Martina:)

Buen lab!!!! 🙌🏼 Todo es correcto. Las funciones serán muy útiles para ahorrar tiempo y simplificar código, así que está bien pillarles el "truquillo":) Te dejo algunas maneras de resolver las últimas 2 preguntas:

  • 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

Tu código no funciona por varias cosas. En primer lugar la lista de carácteres no está bien definida, ya que se debe hacerse como una cadena de caracteres con comillas:) Además, la manera en la que se comprueban las condiciones no es correcta. Te dejo una posible manera de resolverlo, debería funcionarte!

También te dejo 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)

Felicidades!! 💪🏼 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