Skip to content

Instantly share code, notes, and snippets.

Avatar
🔨
Building

Cozy! ItsCosmas

🔨
Building
View GitHub Profile
View raise.py
# RAISING EXCEPTIONS
print("Some Text")
raise ValueError
print("Something Else")
# Detail Exception
name = "1234"
raise NameError("Invalid Name")
# Raise in Except
View exceptions_1.py
try:
word = "spam"
print(word/0)
except:
print("An Error Occured")
finally:
print("This code will run no matter what errors")
View exceptions.py
try:
num = "cos"
num2 = 2
div = num2/num
except ZeroDivisionError:
print("An Error due to zero Division")
except (ValueError, TypeError):
print("An Error occured")
else:
print("The answer is: " + str(div))
View try_except1.py
try:
num = "text"
num2 = 2
ans = num2/num
except TypeError:
print("An Error occured: You cannot perfom division on a string.")
else:
print("The answer is: " + str(ans))
View for_range_2.py
for x in range(2, 30, 3):
print(x)
View for_range_1.py
for i in range(10):
print(i)
View range_3.py
numbers = list(range(5,20, 2))
print(numbers)
View range_2.py
numbers = list(range(3, 10))
print(numbers)
View range_1.py
numbers = list(range(10))
print(numbers)
View for_loop_else.py
for x in range(6):
print(x)
else:
print("Finally finished!")