Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sample/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def multiply(a, b):

def divide(a, b):
if b == 0:
return "Cannot divide by zero!"
raise ValueError("Cannot divide by zero!")
return a / b


Expand Down
23 changes: 16 additions & 7 deletions sample/file_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
def read_file(filepath):
with open(filepath, "r") as f:
data = f.read()
return data
def read_file(filepath: str) -> str:
try:
with open(filepath, "r") as f:
return f.read()
except FileNotFoundError:
print(f"File not found: {filepath}")
return ""
except IOError as e:
print(f"Error reading file {filepath}: {e}")
return ""

def write_file(filepath, content):
with open(filepath, "w") as f:
f.write(content)
def write_file(filepath: str, content: str) -> None:
try:
with open(filepath, "w") as f:
f.write(content)
except IOError as e:
print(f"Error writing to file {filepath}: {e}")


# def read_file(filepath: str) -> str:
Expand Down
15 changes: 7 additions & 8 deletions sample/user.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
class User:
def __init__(self, username, email):
def __init__(self, username: str, email: str):
self.username = username
self.email = email
self.logged_in = False

def login(self):
def login(self) -> None:
self.logged_in = True

def logout(self):
def logout(self) -> None:
self.logged_in = False

def is_logged_in(self):
def is_logged_in(self) -> bool:
return self.logged_in

def update_email(self, new_email):
def update_email(self, new_email: str) -> None:
if "@" not in new_email:
print("Invalid email address!")
else:
self.email = new_email
raise ValueError("Invalid email address")
self.email = new_email


# class User:
Expand Down