Skip to content

errhand_MIKI_PUIG#17

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

errhand_MIKI_PUIG#17
Miquelpg6 wants to merge 1 commit intoIronhack-data-bcn-oct-2023:mainfrom
Miquelpg6:main

Conversation

@Miquelpg6
Copy link
Copy Markdown

No description provided.

@bripollc
Copy link
Copy Markdown

Hello Miki:)

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

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

Te dejo una manera de hacerlo con comprehension lists:) jajja ojo con 'vawels', que no significa nada xd

  • Find all the consonants in the sentence 'The quick brown fox jumped over the lazy dog'.
sentance_2 = 'The Quick Brown Fox Jumped Over The Lazy Dog'
list_vowels = ["a", "e", "i", "o", "u"]
consonants = [char for char in sentance_2 if char not in list_vowels and char != ' ']
print(consonants)

Si añades and char != ' ' en tu comprehension list eliminarás los espacios en blanco.

  • 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 específica 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 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