From f3415c0c4c0ee1f715a76d891a3e8df0f23bfe54 Mon Sep 17 00:00:00 2001 From: Gift_M Date: Wed, 18 Dec 2024 20:06:35 +0200 Subject: [PATCH 1/2] Functions to test passed --- banking_app/user_management.py | 2 +- functions_to_test.py | 77 +++++++++++++++++++++++++++++----- 2 files changed, 67 insertions(+), 12 deletions(-) diff --git a/banking_app/user_management.py b/banking_app/user_management.py index fd7d1e0..26ca2cb 100644 --- a/banking_app/user_management.py +++ b/banking_app/user_management.py @@ -1,4 +1,4 @@ -import csv + bimport csv DATABASE_FILE = "banking_app/database.csv" diff --git a/functions_to_test.py b/functions_to_test.py index 330fa02..0086993 100644 --- a/functions_to_test.py +++ b/functions_to_test.py @@ -1,34 +1,84 @@ # Placeholder functions for Python basics, to be implemented later +import math + def add_numbers(a, b): - pass + return(a+b) + def find_maximum(a, b, c): - pass + list1 = [a,b,c] + return(max(list1)) +print(find_maximum(4,5,6)) def is_palindrome(string): - pass + if type(string) == str: + string = string.lower() + string1 = string[::-1] + return(string==string1) + else: + raise TypeError def count_word_occurrences(text, word): - pass + if type(word) == str and type(text) == str: + text1 = text.lower() + word1= word.lower() + word_count = text1.count(word1) + return (word_count) + else: + raise TypeError + + def read_file_lines(filepath): - pass + with open(filepath,"r") as file: + lines = file.readlines() + return(lines) def factorial(n): - pass + if n < 0: + raise ValueError + elif type(n) != int: + raise TypeError + from math import factorial as factors + return factors(n) + def is_prime(n): - pass + if n < 0 : + raise ValueError + elif n <= 1: + return False + elif type(n) != int : + raise TypeError + for i in range(2,n): + if n % i == 0: + return False + return True + + + def sort_numbers(numbers): - pass + for i in numbers: + if type(i) == str: + raise TypeError + return sorted(numbers) def factorial(n): - pass + if n < 0: + return "" + elif type(n) != int: + raise TypeError + from math import factorial as factors + return factors(n) def fibonacci(n): - pass + if n == 0: + return 0 + elif n == 1: + return 1 + return(fibonacci(n-1)+fibonacci(n-2)) def tower_of_hanoi(n, source, auxiliary, target): @@ -52,7 +102,12 @@ def tower_of_hanoi(n, source, auxiliary, target): class Person: def __init__(self, name, age): - pass + if type(name) == str and type(age) == int: + self.name = name + self.age = age + return + else: + return TypeError if __name__ == "__main__": From 73c7048e2a3f38a50f8d10ac3521ea2cd2cfcc06 Mon Sep 17 00:00:00 2001 From: Gift_M Date: Fri, 20 Dec 2024 15:19:21 +0200 Subject: [PATCH 2/2] Still progressing --- banking_app/login.py | 18 ++++++++++++++++++ functions_to_test.py | 5 +---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/banking_app/login.py b/banking_app/login.py index 2bbab36..2ffea2a 100644 --- a/banking_app/login.py +++ b/banking_app/login.py @@ -1,4 +1,6 @@ # login.py - Placeholder for login functionality +import string +import hashlib def login(username, password): """ @@ -33,3 +35,19 @@ def login(username, password): - bool: `True` if login is successful, `False` if login fails, or raises a `ValueError` for invalid input. """ + + special_characters = "!@#$%^&*()_+-=[]{}|;:'\,.<>?/`~" + users = {"user1": hashlib.sha256("password123".encode()).hexdigest()} + if username == "" or password == "": + raise ValueError + if any(i in username for i in special_characters): + raise ValueError + if not username: + return False + if username in users: + stored_password = users[username] + return stored_password == hashlib.sha256(password.encode()).hexdigest() + return False + + +login("fjbnrf","furjg#") \ No newline at end of file diff --git a/functions_to_test.py b/functions_to_test.py index 0086993..c6dc857 100644 --- a/functions_to_test.py +++ b/functions_to_test.py @@ -54,10 +54,7 @@ def is_prime(n): for i in range(2,n): if n % i == 0: return False - return True - - - + return True def sort_numbers(numbers): for i in numbers: