Skip to content

Instantly share code, notes, and snippets.

View Ventsislav-Yordanov's full-sized avatar

Ventsislav Yordanov Ventsislav-Yordanov

View GitHub Profile
try:
print(int("Hello"))
except NameError:
print("A NameError occured")
except TypeError:
print("A TypeError occured")
except ValueError:
print("A ValueError occured")
except:
print("Another type of error occured")
try:
print(numbers)
except NameError:
print("An NameError occured")
try:
# Write your operations here
print(numbers)
except:
# If there is an error, the code in this block will be executed
# For example, here you can log the error details
print("An exception occured")
def check_anagrams(word1, word2):
"""
Check if the two passed words are anagrams.
Returns True if the word1 and word2 are anagrams, otherwise returns False
"""
if type(word1) != str or type(word2) != str:
raise TypeError("The word1 and word2 must be strings")
return sorted(word1) == sorted(word2)
def check_anagrams(word1, word2):
"""
Check if the two passed words are anagrams.
Returns True if the word1 and word2 are anagrams, otherwise returns False
"""
return sorted(word1) == sorted(word2)
print(check_anagrams("silent", "listen"))
print(check_anagrams("silent", 5))
print(int(6.99))
print(int("7"))
print(int("Hi"))
def print_message(text):
print(text)
print_message()
def print_info(name, position, email):
print("name:", name)
print("position:", position)
print("email:", email)
details = {"email": "[email protected]", "position": "data analyst"}
print_info("Jake", **details)
def print_info(name, position, email):
print("name:", name)
print("position:", position)
print("email:", email)
details = ("data analyst", "[email protected]")
print_info("Jake", *details)
def get_average(*arguments):
return sum(arguments) / len(arguments)
print(get_average(5, 10, 15))
print()
def print_info(**key_value_pairs):
for key, value in key_value_pairs.items():
print(key, value)