Python Basics NOTES 2 (try & except)
# Try Except :
print("Enter two numbers below : ")
num1 = input()
num2 = input()
try:
print(f"The sum of the numbers is : {int(num1) + int(num2)}")
print("The sum of the two numbers is : ",int(num1) + int(num2))
except Exception as x:
print(x)
print("THIS STATEMENT IS VERY IMPORTANT\n")
# We use "try" when we want the program not to terminate when an error is occured. "try" & "Exception" makes the program to print error as an string.
# File IO Basics :
"""
"r" - opens for reading
"w" - opens for writing
"x" - creates a file if not exists
"a" - add more content to a file
"t" - text mode
"b" - binary mode
"+" - raed and write
"""

Comments
Post a Comment