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