Skip to content

[Felix] lab errhand listcomp#22

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

[Felix] lab errhand listcomp#22
imfap1 wants to merge 1 commit intoIronhack-data-bcn-oct-2023:mainfrom
Ironhack-Bootcamp:main

Conversation

@imfap1
Copy link
Copy Markdown

@imfap1 imfap1 commented Oct 16, 2023

image

@bripollc
Copy link
Copy Markdown

Hello Felix:)

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

  • 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 = [nums for nums in range(1, 1001) if nums % 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

  • Flatten the following list of lists. Use flatten_list as the name of the output.
flatten_list = [i for sublist in list_of_lists for i in sublist]
print(flatten_list)

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. (division by 0)
try:
    z = x/y
except ZeroDivisionError:
    print(f"I cannot divide a number by {y}")

Tu respuesta es correcta y funciona! Solo quería que supieras que la excepción ZeroDivisionError es más especifica para este error en concreto.

  • Handle the exception thrown by the code below by using try and except blocks. (index)

Idem que el ejercicio anterior pero con 'IndexError'.

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 siguiente laaaaaab! 💥🚀

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