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
23 changes: 22 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 csv
def login(username, password):
"""
Handles the user login process by verifying the provided username and password.
Expand Down Expand Up @@ -33,3 +33,24 @@ def login(username, password):
- bool: `True` if login is successful, `False` if login fails, or raises a `ValueError` for invalid input.

"""

if not username or not password:
raise ValueError

for char in username:
if not char.isalnum():
raise ValueError()


path = r"C:\Users\User\Byte-me-python\database.csv"
with open(path, mode='r', newline='', encoding='utf-8') as file:
reader = csv.reader(file)
for row in reader:

if username in row and row[username] == password:
return True
else:
return False

return True

18 changes: 17 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,19 @@ def signup(username, password, email):
Returns:
- bool: `True` if the signup is successful, otherwise raises a `ValueError` for invalid input.
"""

if not username or not password or not email:
raise ValueError()

email_regex = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
if not re.match(email_regex, email):
raise ValueError()


if len(password) < 8 or not any(c.isupper() for c in password) or not any(c.islower() for c in password) or not any(c.isdigit() for c in password):
raise ValueError()

if password.isdigit() or password.lower() in ["password", "123456", "qwerty"]:
raise ValueError()

return True
91 changes: 80 additions & 11 deletions functions_to_test.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,97 @@
# Placeholder functions for Python basics, to be implemented later

def add_numbers(a, b):
pass
if not isinstance(a, (int,float)) or not isinstance(b, (int,float)):
raise TypeError

return a + b


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

def is_palindrome(string):
pass
if not type(string) == str:
raise TypeError

return string == string[::-1]

def count_word_occurrences(text, word):
pass
if type(text) == int:
raise TypeError
return text.lower().count(word)

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

def factorial(n):
pass
if not isinstance(n, int):
raise TypeError()

if n < 0:
raise ValueError()

if n == 0 or n == 1:
return 1

return n * factorial(n - 1)


def is_prime(n):
pass
if not isinstance(n, int):
raise TypeError()

if n < 0:
raise ValueError()

if n < 2:
return False

for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False

return True

def sort_numbers(numbers):
pass
for i in numbers:
if not isinstance(i, int):
raise TypeError()

return sorted(numbers)

def factorial(n):
pass
if not isinstance(n, int):
raise TypeError()

if n < 0:
raise ValueError()

if n == 0 or n == 1:
return 1

return n * factorial(n - 1)


def fibonacci(n):
pass
if not isinstance(n, int):
raise TypeError()

if n < 0:
raise ValueError()

if n == 0:
return 0
if n == 1:
return 1

a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b

return b


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

Expand All @@ -52,7 +115,13 @@ def tower_of_hanoi(n, source, auxiliary, target):

class Person:
def __init__(self, name, age):
pass
if not isinstance(name, str):
raise TypeError("Name must be a string.")
if not isinstance(age, int):
raise TypeError("Age must be an integer.")

self.name = name
self.age = age


if __name__ == "__main__":
Expand Down
7 changes: 3 additions & 4 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ def test_factorial_0_and_1(self):
1)


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

def test_factorial_negative(self):
with self.assertRaises(ValueError):
factorial(-1)

def test_factorial_5(self):
self.assertEqual(factorial(5),
Expand Down