diff --git a/ciphers/des_ecb.py b/ciphers/des_ecb.py index 4c904294a2d4..559aee9b764a 100644 --- a/ciphers/des_ecb.py +++ b/ciphers/des_ecb.py @@ -537,21 +537,26 @@ def decrypt(key: str, cipher_text: str) -> str: if mode not in ["e", "d", "k", "q"]: print("Invalid option. Please try again.") continue - if mode == "q": - break - elif mode == "k": - print(f"Generated key: {Des.generate_key()}") - elif mode == "e": - key = input("Enter the key: ").strip() - if len(key) != 16 and not all(char in "0123456789abcdef" for char in key): - print("Invalid key. Please try again.") - continue - input_string = input("Enter the string to encrypt: ").strip() - print(f"Encrypted string: {Des.encrypt(key, input_string)}") - elif mode == "d": - key = input("Enter the key: ").strip() - if len(key) != 16 and not all(char in "0123456789abcdef" for char in key): - print("Invalid key. Please try again.") - continue - cipher_text = input("Enter the cipher text to decrypt: ").strip() - print(f"Decrypted string: {Des.decrypt(key, cipher_text)}") + match mode: + case "q": + break + case "k": + print(f"Generated key: {Des.generate_key()}") + case "e": + key = input("Enter the key: ").strip() + if len(key) != 16 and not all( + char in "0123456789abcdef" for char in key + ): + print("Invalid key. Please try again.") + continue + input_string = input("Enter the string to encrypt: ").strip() + print(f"Encrypted string: {Des.encrypt(key, input_string)}") + case "d": + key = input("Enter the key: ").strip() + if len(key) != 16 and not all( + char in "0123456789abcdef" for char in key + ): + print("Invalid key. Please try again.") + continue + cipher_text = input("Enter the cipher text to decrypt: ").strip() + print(f"Decrypted string: {Des.decrypt(key, cipher_text)}") diff --git a/financial/exponential_moving_average.py b/financial/exponential_moving_average.py index b56eb2712415..85622295231d 100644 --- a/financial/exponential_moving_average.py +++ b/financial/exponential_moving_average.py @@ -19,6 +19,9 @@ def exponential_moving_average( Yields exponential moving averages of the given stock prices. >>> tuple(exponential_moving_average(iter([2, 5, 3, 8.2, 6, 9, 10]), 3)) (2, 3.5, 3.25, 5.725, 5.8625, 7.43125, 8.715625) + >>> tuple(exponential_moving_average(iter([10.0, 20.0, 30.0]), 1)) + (10.0, 20.0, 30.0) + :param stock_prices: A stream of stock prices :param window_size: The number of stock prices that will trigger a new calculation @@ -49,7 +52,7 @@ def exponential_moving_average( moving_average = 0.0 for i, stock_price in enumerate(stock_prices): - if i <= window_size: + if i < window_size: # Assigning simple moving average till the window_size for the first time # is reached moving_average = (moving_average + stock_price) * 0.5 if i else stock_price