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: 18 additions & 0 deletions banking_app/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,21 @@ def login(username, password):
- bool: `True` if login is successful, `False` if login fails, or raises a `ValueError` for invalid input.

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

symbol = "!@#$%^&*()_+={}[]|:;'\"<>,.?/"
for char in username:
if char in symbol:
raise ValueError

valid1 = "user1"
valid2 = "securepassword123"

if username == valid1 and password == valid2:
return True
else:
return False
except:
raise
19 changes: 19 additions & 0 deletions banking_app/signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,22 @@ def signup(username, password, email):
Returns:
- bool: `True` if the signup is successful, otherwise raises a `ValueError` for invalid input.
"""

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

if len(password) < 6:
raise ValueError

if "@" not in email or "." not in email:
raise ValueError

existing = ["existinguser"]

if username in existing:
raise ValueError

return True
except:
raise
42 changes: 41 additions & 1 deletion banking_app/transaction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# transaction.py - Placeholder for transaction functionality

from banking_app.user_management import read_users,write_users
def transact(sender_account, receiver_account, amount):
"""
Handles the transfer of funds between two user accounts.
Expand Down Expand Up @@ -44,4 +44,44 @@ 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 sender_account == receiver_account:
raise ValueError

if amount <= 0:
raise ValueError

try:
users = read_users()

sender = None
receiver = None

for user in users:
if user["account_id"] == sender_account:
sender = user

if user["account_id"] == receiver_account:
receiver = user

if sender_account == "" or receiver_account == "":
raise ValueError

if sender["balance"] < amount:
raise ValueError

sender["balance"] -= amount
receiver["balance"] += amount

write_users(users)

return True

except:
raise



129 changes: 117 additions & 12 deletions functions_to_test.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,131 @@
# Placeholder functions for Python basics, to be implemented later

def add_numbers(a, b):
pass
if type(a) != int or type(b) != int:
raise TypeError

try:
sum = a + b
return sum
except:
raise TypeError

def find_maximum(a, b, c):
pass
if type(a) != int or type(b) != int or type(c) != int:
raise TypeError

try:
high = max(a,b,c)
return high
except:
TypeError

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

string = string.replace(" ","")
reversed_word = string[::-1]
return string.lower() == reversed_word.lower()
except:
raise

def count_word_occurrences(text, word):
pass
try:
if type(text) != str or type(word) != str:
raise TypeError
text = text.lower()
word = word.lower()
list1 = text.split()
return list1.count(word)
except:
raise

def read_file_lines(filepath):
pass
try:
if type(filepath) != str:
raise TypeError
with open(filepath, 'r') as f:
return f.readlines()
except:
raise

def factorial(n):
pass
try:
if type(n) != int:
raise TypeError
if n < 0:
raise ValueError
if n == 0:
return 1
result = 1
for i in range(1,n +1):
result *= i
return result
except:
raise



def is_prime(n):
pass
try:
if type(n) != int:
raise TypeError

if n < 0:
raise ValueError
if n < 2:
return False
number = int(n ** 0.5) + 1
for j in range(2,number):
if n % j == 0:
return False
return True
except:
raise

def sort_numbers(numbers):
pass
try:
for x in numbers:
if type(x) != int:
raise TypeError
except:
raise

return sorted(numbers)

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

result = 1
for i in range(1,n +1):
result *= i
return result
except:
raise

def fibonacci(n):
pass
try:
if type(n) != int:
raise TypeError
if n < 0:
raise ValueError
if n == 0:
return 0
elif n == 1:
return 1

x,z = 0,1
for _ in range(2, n+1):
x,z = z, x +z
return z
except:
raise

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

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

class Person:
def __init__(self, name, age):
pass

try:
if type(name) != str:
raise TypeError
if type(age) != int:
raise TypeError

self.name = name
self.age = age
except:
raise

if __name__ == "__main__":
# Placeholder functions for Python basics, to be implemented later
Expand Down