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

[Felix] lab errhand listcomp #22

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

Conversation

imfap1
Copy link

@imfap1 imfap1 commented Oct 16, 2023

image

@bripollc
Copy link

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