Skip to content

Leon#19

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

Leon#19
leonplaza wants to merge 1 commit intoIronhack-data-bcn-oct-2023:mainfrom
leonplaza:main

Conversation

@leonplaza
Copy link
Copy Markdown

No description provided.

@bripollc
Copy link
Copy Markdown

Hello León:)

Te dejo algunas cosillas pero buen lab en general!! Poco a poco la cosa va cogiendo ritmo:) Felicidades 💥

  • Calculate the square root of the first 100 numbers. Use sqrt as the name of the list.
sqrt = list(map(lambda x: math.sqrt(x), range(1,101)))
sqrt

Te pide la raíz cuadrada los 100 primeros números, en tu rango especificas range(0,21) 🫠 pequeño despiste jeje

  • Find all of the numbers from 1-1000 that are divisible by 7. Use divisible_by_seven as the name of the list.
divisible_by_seven = [x for x in range(1,1001) if x%7 == 0]
print(divisible_by_seven)

Te pide los números divisibles entre 7 de 1-1000, en tu rango especificas range(1, 101) 🫠 pequeño despiste jeje

  • 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.
vowels = "aeiouAEIOU"
non_vowels = [i for i in teststring if i.lower() not in vowels and i != ' ']
print(non_vowels)

Tu código es OK!! Te dejo otra manera de hacerlo para que no tengas que importar el módulo de 'functools'.

  • Find the folders you have in your lectures local repo. Use files as name of the list.
path = "../../lectures"     -- your path here:)
files = [os.listdir(path)]

from os import listdir
filenames = [f for f in listdir(path)]
print(filenames)
  • Create 4 lists of 10 random numbers between 0 and 100 each. Use random_lists as the name of the list.
random_lists = [[random.randrange(n,101) for n in range(0,10)] for i in range(0,5)]
print(random_lists)

Te dejo una manera de solucionarlo:) Tu approach no es del todo correcto.

  • Handle the exception thrown by the code below by using try and except blocks. (printing strings)
for i in ['a','b','c']:
    try:
        print (i**2)
    except:
        print(f"I cannot square the element of your list {i}")

Te dejo el BONUS también:

  • 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") 

A por el próximo laaaaaaab! 💥

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