This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
print(numbers) | |
except NameError: | |
print("An NameError occured") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(int(6.99)) | |
print(int("7")) | |
print(int("Hi")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_message(text): | |
print(text) | |
print_message() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_info(name, position, email): | |
print("name:", name) | |
print("position:", position) | |
print("email:", email) | |
details = ("data analyst", "[email protected]") | |
print_info("Jake", *details) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |