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
18 changes: 17 additions & 1 deletion banking_app/login.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# login.py - Placeholder for login functionality

import re
def login(username, password):
"""
Handles the user login process by verifying the provided username and password.
Expand Down Expand Up @@ -33,3 +33,19 @@ def login(username, password):
- bool: `True` if login is successful, `False` if login fails, or raises a `ValueError` for invalid input.

"""

if username == "" or password == "":
raise ValueError

if not re.match(r"^[a-zA-Z0-9]{3,}$", username):
raise ValueError

with open("database.csv", "r", errors="ignore") as f:
contents = f.readlines()
for user in contents:
user.replace("\n", "")
saved_username, saved_password, other = user.split(",", 2)

if username == saved_username and password == saved_password:
return True
return False
31 changes: 30 additions & 1 deletion banking_app/signup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# signup.py - Placeholder for signup functionality

import re
def signup(username, password, email):
"""
Handles the user signup process by validating the provided username, password, and email.
Expand Down Expand Up @@ -35,3 +35,32 @@ def signup(username, password, email):
Returns:
- bool: `True` if the signup is successful, otherwise raises a `ValueError` for invalid input.
"""
if username == "" or password == "" or email == "":
raise ValueError

if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
raise ValueError

pass_pattern = r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(.{8,})$"
if not re.match(pass_pattern, password):
raise ValueError

"""
username,password,email,account_id,balance
johndoe,hashed_password,johndoe@example.com,account1,1000.50
"""

with open("database.csv", "r", errors="ignore") as f:
contents = f.readlines()
for user in contents:
user.replace("\n", "")
saved_username, other = user.split(",", 1)
if username == saved_username:
raise ValueError

with open("database.csv", "a") as f:
f.write(f"{username},{password},{email}")
return True

if __name__ == "__main__":
signup("newuser", "SecurePass123", "newuser@example.com")
4 changes: 4 additions & 0 deletions banking_app/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ def transact(sender_account, receiver_account, amount):
"""

#hint should use read_users and write_users from user_management
if sender_account == "" or receiver_account == "":
raise ValueError
if amount <= 0:
raise ValueError

71 changes: 58 additions & 13 deletions functions_to_test.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,73 @@
# Placeholder functions for Python basics, to be implemented later

from math import factorial as fac
def add_numbers(a, b):
pass
return a+b

def find_maximum(a, b, c):
pass
return max([a,b,c])

def is_palindrome(string):
pass
if not isinstance(string, str):
raise TypeError
return string==string[::-1]

def count_word_occurrences(text, word):
pass
count = 0
if not isinstance(text, str):
raise TypeError
for wd in text.split():
if wd.lower() == word.lower():
count += 1
return count

def read_file_lines(filepath):
pass
with open(filepath, "r", errors="ignore") as f:
return f.readlines()

def factorial(n):
pass
if not isinstance(n, int):
raise TypeError
if n < -1:
raise ValueError
if n == -1:
return 1
return fac(n)

def is_prime(n):
pass
if n < 0:
raise ValueError
if not isinstance(n, int):
raise TypeError
if n <= 1:
return False
if n == 2 or n == 3 or n == 5:
return True
if n == 4:
return False
for num in range (2, int(n/2)):
if n % num == 0:
return False
return True

def sort_numbers(numbers):
pass
if len(numbers) == 0:
return []
if not isinstance(numbers[0], int):
raise TypeError
return sorted(numbers)

def factorial(n):
pass
if not isinstance(n, int):
raise TypeError
if n < -1:
raise ValueError
if n == -1:
return 1
return fac(n)

def fibonacci(n):
pass
fib = lambda x: x if x <= 1 else fib(x -1) + fib(x-2)
return fib(n)

def tower_of_hanoi(n, source, auxiliary, target):

Expand All @@ -52,10 +91,16 @@ def tower_of_hanoi(n, source, auxiliary, target):

class Person:
def __init__(self, name, age):
pass
if not isinstance(name, str):
raise TypeError
if not isinstance(age, int):
raise TypeError
self.name = name
self.age = age


if __name__ == "__main__":
# Placeholder functions for Python basics, to be implemented later
#to test your functions, you can use the following code
print(add_numbers(3, 5)) #e.g
print(add_numbers(3, 5)) #e.g
print(fibonacci(5))
3 changes: 1 addition & 2 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def test_factorial_0_and_1(self):


def test_factorial_negative(self):
self.assertEqual(factorial(-1),
"")
self.assertEqual(factorial(-1),1)


def test_factorial_5(self):
Expand Down