Day 3 Python
Day 3/20
On day 3 of your Python learning journey, you should continue working through the Codecademy Python course and solving exercises on HackerRank to get more hands-on practice with the language. You can also start thinking about a small project you would like to work on using the skills you have learned so far.
Here are a few examples of concepts you might encounter on day 3, along with some code snippets that demonstrate how they work:
File handling:
# reading a file
with open("file.txt", "r") as f:
contents = f.read()
# writing to a file
with open("file.txt", "w") as f:
f.write("Hello, world!")
Exception handling:
try:
x = int(input("Enter a number: "))
print(x / y)
except ZeroDivisionError:
print("Cannot divide by zero")
except ValueError:
print("Invalid input")
Modules:
# importing a module
import math
# using a function from the module
print(math.sqrt(16)) # 4.0
# importing a specific function from a module
from math import sqrt
print(sqrt(16)) # 4.0
I hope that these Python Preparation Plans will help you enhance your interest in programming as well as python and then all python topics. Please feel free to provide insightful remarks in the space below.