Skip to content

Junior - lab err done#18

Open
linharesjunior wants to merge 2 commits intoIronhack-data-bcn-oct-2023:mainfrom
linharesjunior:main
Open

Junior - lab err done#18
linharesjunior wants to merge 2 commits intoIronhack-data-bcn-oct-2023:mainfrom
linharesjunior:main

Conversation

@linharesjunior
Copy link
Copy Markdown

No description provided.

@bripollc
Copy link
Copy Markdown

Hello Junior:)

I'll leave you some little details but good lab in general! Gradually the things are getting rhythm:) Congratulations 💥

  • Create this list [-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0]. Use my_list as the name of the list.
my_list = [i for i in range(-10,1)]
print(my_list)

Your code gives a correct result but I leave you a way to do it with comprehension lists.

  • Remove all of the vowels in a string. Hint: make a list of the non-vowels. Use non_vowels as the name of the list.
non_vowels = [x for x in teststring if x.lower() not in 'aeiou' and x != ' ']
print(non_vowels)

Your answer is absolutely correct! Just a little tip to simplify the code :) If you add and x != ' ', you will remove the spaces from the list at once in your comprehension list without the need to create the result_string . By doing "".join you are returning a string, not a list.

I leave you the BONUS as well:

  • Bonus 1
 def square_cal():
    x = input("Insert an integer to square")
    integer=False
    while integer == False:
        try:
            x= int(x)
            integer == True
            return x**2
        except ValueError as error:
            x = input(f"{error}, please insert an valid integer to square")
square_cal()
  • Bonus 2
 results = list(set([num for div in range(2,10) for num in range(1,1001) if num%div == 0]))
print(results)
  • Bonus 3
 class NumSectionsError(Exception):
    pass
while True:
    try:
        Total_Marks = int(input("Enter Total Marks Scored: "))
        break
    except ValueError as error:
        print(error)
while True:
    try:
        Num_of_Sections = int(input("Enter Num of Sections: "))
        if Num_of_Sections > 2:
            raise NumSectionsError
        else:
            break
    except ValueError as error:
        print(error)
    except NumSectionsError:
        print("The number of sections can't be bigger than 2") 

Let's go for the next laaaaaaaab! 💥

image

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