Skip to content

lab-functions#19

Open
sarabenitezinglott wants to merge 1 commit intoIronhack-data-bcn-oct-2023:mainfrom
Ironhack-data23:main
Open

lab-functions#19
sarabenitezinglott wants to merge 1 commit intoIronhack-data-bcn-oct-2023:mainfrom
Ironhack-data23:main

Conversation

@sarabenitezinglott
Copy link
Copy Markdown

I haven't finished exercise 9 :(((

@sh-ih
Copy link
Copy Markdown

sh-ih commented Oct 16, 2023

Sara,

Great job on this lab! ⭐

Some comments:

On Question 1, you left the pass keyword on your function. Pass acts as a placeholder for future code and to avoid getting an error when empty code is not permitted. For example, if you try to run only:
def sum(a,b):
you’ll get an error, but if you run

def sum(a,b): 
pass

then no error appears. In this case, you already added your code to add a and b, so the pass keyword is no longer needed.

On question 2, your function passes the test but there is a case where setting largest=0 would create some issues: when your array has only negative numbers. If you run: greatest([-1,-5,-800]) you’ll get 0 as result, instead of -1.
A way to deal with this cases is to set largest=+inf In Python, +inf is an unbounded upper value.
Another option would be to set largest=arr[0]

On question 5, you could simplify your code by calling the functions you created on the previous two questions:

def oper_all(arr, oper):
    if oper == "+":
        return sum_all(arr)
    elif oper == "*":
        return mult_all(arr)

Regarding question 9, the string that the functions gets as an argument can have any characters, you just need to check if the strings contains all the letters of the alphabet. So there is no need to clean the string.

Right now, you defined alphabet = "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"

But remember that to define a list (in this case a list of strings), we need to use square brackets:
alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

Now, you would have to iterate along your alphabet list and check if each element is in string. If not, then the string is not a pangram and you return False. But if you end the iteration along all the elements of alphabet and find all the letters on your string, then you return True:

def pangram(string):
    alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
    for i in alphabet:
        if i not in string.lower(): 
            return False
    return True

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