Skip to content

Instantly share code, notes, and snippets.

View ItsCosmas's full-sized avatar
🔨
Building

Cozy! ItsCosmas

🔨
Building
View GitHub Profile
for x in range(6):
print(x)
else:
print("Finally finished!")
numbers = list(range(10))
print(numbers)
numbers = list(range(3, 10))
print(numbers)
numbers = list(range(5,20, 2))
print(numbers)
for i in range(10):
print(i)
for x in range(2, 30, 3):
print(x)
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))
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))
try:
word = "spam"
print(word/0)
except:
print("An Error Occured")
finally:
print("This code will run no matter what errors")
# RAISING EXCEPTIONS
print("Some Text")
raise ValueError
print("Something Else")
# Detail Exception
name = "1234"
raise NameError("Invalid Name")
# Raise in Except