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

Em : functions lab without exercise 12 - me petaba ya la cabeza #11

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

Conversation

emmacunill
Copy link

No description provided.

@bripollc
Copy link

Emma:)

Las funciones pueden ser mindblowinggggg pero te ahorrarán mucho tiempo y simplificación de código. EPPPP muy muy muy buen trabajo 🌻 Felicitats!!

  • 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_ = 0
    mult_ = 1
    for i in arr:
        if oper == "+":
            sum_ += i
        elif oper == "*":
            mult_ *= i
            
    if oper == "+":    -- Incluir esta parte
        return sum_
    elif oper == "*":
        return mult_

Si ejecutas tu código varias veces, aveces pasa el test y aveces no:) El problema está en la línea return sum_ or mult_. Utilizando el or lo que estás haciendo es: si el primer valor sum_ es verdadero, se devuelve ese valor. Si el primer valor es falso, se devuelve el segundo valor mult_ sin importar su valor. Modificando la parte que te especifico arriba debería funcionarte.

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

Fins demà!!!!!!!

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