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
35 changes: 35 additions & 0 deletions banking_app/login.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
# login.py - Placeholder for login functionality

def login(username, password):
Expand Down Expand Up @@ -33,3 +34,37 @@ def login(username, password):
- bool: `True` if login is successful, `False` if login fails, or raises a `ValueError` for invalid input.

"""
if validate_input(username,password):
if authenticate_user(username, password):
return True

return False

def validate_input(username, password):
if username == "" or password == "":
raise ValueError("Can not have empty password or username")

if username.isalnum() == False:
raise ValueError("Username can not have special characters")

return True

def authenticate_user(username,password):
try:
with open("database.csv", "r") as file:
people = file.readlines()
except FileNotFoundError:
sys.exit("Database not found")

for person in people:
person = person.split(",")
if username in person:
return password_validation(password, person[1])

return False

def password_validation(password1 , password2):
if password1 == password2:
return True
else:
return False
43 changes: 43 additions & 0 deletions banking_app/signup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
# signup.py - Placeholder for signup functionality

def signup(username, password, email):
Expand Down Expand Up @@ -35,3 +36,45 @@ def signup(username, password, email):
Returns:
- bool: `True` if the signup is successful, otherwise raises a `ValueError` for invalid input.
"""

if validate_input(username, password, email):
return True
else:
raise ValueError("Invalid Input")

def validate_input(username, password, email):
if username == "" or password == "" or email == "":
raise ValueError("Inputs can not me empty")

"at least 8 characters long, contains a mix of uppercase, lowercase, and digits"
length = password<8
upper = password.isupper()
lower = password.islower()
digits = password.isalpha()

result = (length and upper and lower and digits)

match result:
case True:
return True
case False:
return False

def check_username(username):
try:
with open("database.csv", "r") as file:
people = file.readlines()
except FileNotFoundError:
sys.exit("Database not found")

for person in people:
person = person.split(",")
if username == person[0]:
raise ValueError("Username already taken")

return True

def create_user(username, password, email):
try:
with open("database.csv" , "r") as file:

83 changes: 70 additions & 13 deletions functions_to_test.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,84 @@
# Placeholder functions for Python basics, to be implemented later

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
return string == string[::-1]

def count_word_occurrences(text, word):
pass
try:
count = text.lower().count(word.lower())
return count
except AttributeError:
raise TypeError("Text must be string")

def read_file_lines(filepath):
pass
try:
with open(filepath, "r") as file:
lines = file.readlines()
return lines
except FileNotFoundError:
raise FileNotFoundError

def factorial(n):
pass

def is_prime(n):
pass

if n == 1:
return False

if n<0:
raise ValueError

count = 0

try:
for i in range(2,n+1):
if n%i == 0:
count += 1
except TypeError:
raise TypeError

if count == 1:
return True
else:
return False

def sort_numbers(numbers):
pass

for num in numbers:
if type(num) != int:
raise TypeError
return sorted(numbers)



def factorial(n):
pass
if n<0:
raise ValueError
if type(n) != int:
raise TypeError

total = 1
for i in range(1, n+1):
total *= i
print(total)

return total

def fibonacci(n):
pass
if n == 0 or n == 1:
return n

numbers = [0,1]

for _ in range(n-2):
numbers.append(numbers[-1] + numbers[-2])

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

"""
Expand All @@ -48,11 +97,19 @@ def tower_of_hanoi(n, source, auxiliary, target):
>>> tower_of_hanoi(3, 'A', 'B', 'C')
[('A', 'C'), ('A', 'B'), ('C', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('A', 'C')]
"""
pass


class Person:
def __init__(self, name, age):
pass
if type(name) == str:
self.name = name
else:
raise TypeError

if type(age) == str:
raise TypeError
else:
self.age = age


if __name__ == "__main__":
Expand Down
12 changes: 12 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def fibonacci(n):
if n == 0 or n == 1:
return n

numbers = [0,1]

for _ in range(n-2):
numbers.append(numbers[-1] + numbers[-2])

return numbers

print(fibonacci(15))