Skip to content

Amir G - Execises without Bonus :(#3

Open
amirg33 wants to merge 1 commit intoIronhack-data-bcn-oct-2023:mainfrom
Ironhack-Labs-Okt-2023:main
Open

Amir G - Execises without Bonus :(#3
amirg33 wants to merge 1 commit intoIronhack-data-bcn-oct-2023:mainfrom
Ironhack-Labs-Okt-2023:main

Conversation

@amirg33
Copy link
Copy Markdown

@amirg33 amirg33 commented Oct 16, 2023

No description provided.

@bripollc
Copy link
Copy Markdown

Hello Amir:)

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

  • 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 reversed(range(0,11))]
print(my_list)

En tu rango no estás incluyendo el 0 🙃 Además, tal y como tienes planteado el código, debes usar reversed() si quieres ordenar la lista a la inversa para cumplir con el enunciado.

  • 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 un pequeño tip!!!! Si añades and i != ' ', también eliminarás los espacios en blanco y te quedarás únicamente son las consonantes.

  • Find all the consonants in the sentence 'The quick brown fox jumped over the lazy dog'.

Te pide que encuentres todas las consonantes jeje, no las vocales!

  • Handle at least two kind of different exceptions when dividing a couple of numbers provided by the user.
try:
    x=int(input())
    y=int(input())
    z=x/y
    print(z)
except ZeroDivisionError:
    print("can't be calculated since the division cannot be calculated")

except ValueError:
    print("wrong type of character")

The pide 2 excepciones. Esta sería una opción.

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