diff --git a/.github/test_code.py b/.github/test_code.py index 32e8da83..cb64a6b3 100644 --- a/.github/test_code.py +++ b/.github/test_code.py @@ -422,7 +422,7 @@ def get_remote_files(self) -> list: # if not f.endswith('.md'): # continue # files.append(os.path.join(root, f)) - return self.get_files("temp") + return self.get_files(os.path.join("temp", self.repo_name)) def compare(self): local_files = self.get_local_files() diff --git a/Number System/Conversion_In_Python1.py b/Number System/Conversion_In_Python1.py index e093190f..c48946e5 100644 --- a/Number System/Conversion_In_Python1.py +++ b/Number System/Conversion_In_Python1.py @@ -1,4 +1,4 @@ -''' +""" Author: SK Jiyad Github: https://github.com/ZRX-SIGMA Date: 2021-10-09 @@ -26,7 +26,8 @@ The program can be run from the command line as follows: python3 Conversion_In_Python1.py -''' +""" + # Function to convert decimal to binary def decimal_to_binary(decimal): @@ -34,36 +35,48 @@ def decimal_to_binary(decimal): return bin(decimal) except (ValueError, TypeError): return None + + # Function to convert decimal to octal def decimal_to_octal(decimal): try: return oct(decimal) except (ValueError, TypeError): return None + + # Function to convert decimal to hexadecimal def decimal_to_hexadecimal(decimal): try: return hex(decimal) except (ValueError, TypeError): return None + + # Function to convert binary to decimal def binary_to_decimal(binary): try: return int(binary, 2) except (ValueError, TypeError): return None + + # Function to convert octal to decimal def octal_to_decimal(octal): try: return int(octal, 8) except (ValueError, TypeError): return None + + # Function to convert hexadecimal to decimal def hexadecimal_to_decimal(hexadecimal): try: return int(hexadecimal, 16) except (ValueError, TypeError): return None + + # Function to convert binary to octal def binary_to_octal(binary): try: @@ -72,6 +85,7 @@ def binary_to_octal(binary): except (ValueError, TypeError): return None + # Function to convert binary to hexadecimal def binary_to_hexadecimal(binary): try: @@ -80,6 +94,7 @@ def binary_to_hexadecimal(binary): except (ValueError, TypeError): return None + # Function to convert octal to binary def octal_to_binary(octal): try: @@ -88,6 +103,7 @@ def octal_to_binary(octal): except (ValueError, TypeError): return None + # Function to convert octal to hexadecimal def octal_to_hexadecimal(octal): try: @@ -96,6 +112,7 @@ def octal_to_hexadecimal(octal): except (ValueError, TypeError): return None + # Function to convert hexadecimal to binary def hexadecimal_to_binary(hexadecimal): try: @@ -104,6 +121,7 @@ def hexadecimal_to_binary(hexadecimal): except (ValueError, TypeError): return None + # Function to convert hexadecimal to octal def hexadecimal_to_octal(hexadecimal): try: @@ -112,6 +130,7 @@ def hexadecimal_to_octal(hexadecimal): except (ValueError, TypeError): return None + # Main function for user interaction def convert_number(): print("Number Conversion Tool") @@ -178,5 +197,6 @@ def convert_number(): else: print("Invalid choice. Please enter a valid option (0-12).") + if __name__ == "__main__": convert_number() diff --git a/Number System/Conversion_In_Python2.py b/Number System/Conversion_In_Python2.py index bf55054a..ca66ef3c 100644 --- a/Number System/Conversion_In_Python2.py +++ b/Number System/Conversion_In_Python2.py @@ -1,4 +1,4 @@ -''' +""" Author: SK Jiyad Github: https://github.com/ZRX-SIGMA Date: 2023-10-07 @@ -26,7 +26,8 @@ The program can be run from the command line as follows: python3 Conversion_In_Python1.py -''' +""" + # Function to convert decimal to binary def decimal_to_binary(decimal): @@ -41,6 +42,7 @@ def decimal_to_binary(decimal): except (ValueError, KeyError, TypeError): return None + # Function to convert decimal to octal def decimal_to_octal(decimal): try: @@ -54,6 +56,7 @@ def decimal_to_octal(decimal): except (ValueError, KeyError, TypeError): return None + # Function to convert decimal to hexadecimal def decimal_to_hexadecimal(decimal): try: @@ -65,12 +68,13 @@ def decimal_to_hexadecimal(decimal): if remainder < 10: hexadecimal = str(remainder) + hexadecimal else: - hexadecimal = chr(ord('A') + remainder - 10) + hexadecimal + hexadecimal = chr(ord("A") + remainder - 10) + hexadecimal decimal = decimal // 16 return "0x" + hexadecimal except (ValueError, KeyError, TypeError): return None + # Function to convert binary to decimal def binary_to_decimal(binary): try: @@ -78,7 +82,7 @@ def binary_to_decimal(binary): binary = binary[2:] # Remove '0b' prefix decimal = 0 for digit in binary: - if digit not in ('0', '1'): + if digit not in ("0", "1"): raise ValueError("Invalid binary digit: {}".format(digit)) decimal = decimal * 2 + int(digit) return decimal @@ -93,13 +97,14 @@ def octal_to_decimal(octal): octal = octal[2:] # Remove '0o' prefix decimal = 0 for digit in octal: - if not '0' <= digit <= '7': + if not "0" <= digit <= "7": raise ValueError("Invalid octal digit: {}".format(digit)) decimal = decimal * 8 + int(digit) return decimal except ValueError: return None + # Function to convert hexadecimal to decimal def hexadecimal_to_decimal(hexadecimal): try: @@ -107,13 +112,14 @@ def hexadecimal_to_decimal(hexadecimal): hexadecimal = hexadecimal[2:] # Remove '0x' prefix decimal = 0 for digit in hexadecimal: - if not ('0' <= digit <= '9' or 'A' <= digit <= 'F' or 'a' <= digit <= 'f'): + if not ("0" <= digit <= "9" or "A" <= digit <= "F" or "a" <= digit <= "f"): raise ValueError("Invalid hexadecimal digit: {}".format(digit)) decimal = decimal * 16 + int(digit, 16) return decimal except ValueError: return None + # Function to convert binary to octal def binary_to_octal(binary): try: @@ -121,15 +127,18 @@ def binary_to_octal(binary): binary = binary[2:] # Remove '0b' prefix octal = "" while len(binary) % 3 != 0: - binary = '0' + binary # Pad with leading zeros to make it a multiple of 3 + binary = "0" + binary # Pad with leading zeros to make it a multiple of 3 for i in range(0, len(binary), 3): - octal_digit = binary[i:i + 3] + octal_digit = binary[i : i + 3] decimal_value = int(octal_digit, 2) - octal += str(oct(decimal_value))[2:] # Convert to octal without the '0o' prefix + octal += str(oct(decimal_value))[ + 2: + ] # Convert to octal without the '0o' prefix return "0o" + octal except ValueError: return None + # Function to convert binary to hexadecimal def binary_to_hexadecimal(binary): try: @@ -137,15 +146,18 @@ def binary_to_hexadecimal(binary): binary = binary[2:] # Remove '0b' prefix hexadecimal = "" while len(binary) % 4 != 0: - binary = '0' + binary # Pad with leading zeros to make it a multiple of 4 + binary = "0" + binary # Pad with leading zeros to make it a multiple of 4 for i in range(0, len(binary), 4): - hex_digit = binary[i:i + 4] + hex_digit = binary[i : i + 4] decimal_value = int(hex_digit, 2) - hexadecimal += format(decimal_value, 'X') # Convert to uppercase hexadecimal + hexadecimal += format( + decimal_value, "X" + ) # Convert to uppercase hexadecimal return "0x" + hexadecimal except ValueError: return None + # Function to convert octal to binary def octal_to_binary(octal): try: @@ -153,13 +165,16 @@ def octal_to_binary(octal): octal = octal[2:] # Remove '0o' prefix binary = "" for digit in octal: - if not '0' <= digit <= '7': + if not "0" <= digit <= "7": raise ValueError("Invalid octal digit: {}".format(digit)) - binary += format(int(digit, 8), '03b') # Convert to 3-bit binary with leading zeros + binary += format( + int(digit, 8), "03b" + ) # Convert to 3-bit binary with leading zeros return "0b" + binary except ValueError: return None + # Function to convert octal to hexadecimal def octal_to_hexadecimal(octal): try: @@ -167,15 +182,18 @@ def octal_to_hexadecimal(octal): octal = octal[2:] # Remove '0o' prefix hexadecimal = "" while len(octal) % 3 != 0: - octal = '0' + octal # Pad with leading zeros to make it a multiple of 3 + octal = "0" + octal # Pad with leading zeros to make it a multiple of 3 for i in range(0, len(octal), 3): - octal_group = octal[i:i + 3] + octal_group = octal[i : i + 3] decimal_value = int(octal_group, 8) - hexadecimal += format(decimal_value, 'X') # Convert to uppercase hexadecimal + hexadecimal += format( + decimal_value, "X" + ) # Convert to uppercase hexadecimal return "0x" + hexadecimal except ValueError: return None + # Function to convert hexadecimal to binary def hexadecimal_to_binary(hexadecimal): try: @@ -183,13 +201,16 @@ def hexadecimal_to_binary(hexadecimal): hexadecimal = hexadecimal[2:] # Remove '0x' prefix binary = "" for digit in hexadecimal: - if not ('0' <= digit <= '9' or 'A' <= digit <= 'F' or 'a' <= digit <= 'f'): + if not ("0" <= digit <= "9" or "A" <= digit <= "F" or "a" <= digit <= "f"): raise ValueError("Invalid hexadecimal digit: {}".format(digit)) - binary += format(int(digit, 16), '04b') # Convert to 4-bit binary with leading zeros + binary += format( + int(digit, 16), "04b" + ) # Convert to 4-bit binary with leading zeros return "0b" + binary except ValueError: return None + # Function to convert hexadecimal to octal def hexadecimal_to_octal(hexadecimal): try: @@ -197,15 +218,18 @@ def hexadecimal_to_octal(hexadecimal): hexadecimal = hexadecimal[2:] # Remove '0x' prefix octal = "" while len(hexadecimal) % 3 != 0: - hexadecimal = '0' + hexadecimal # Pad with leading zeros to make it a multiple of 3 + hexadecimal = ( + "0" + hexadecimal + ) # Pad with leading zeros to make it a multiple of 3 for i in range(0, len(hexadecimal), 3): - hexadecimal_group = hexadecimal[i:i + 3] + hexadecimal_group = hexadecimal[i : i + 3] decimal_value = int(hexadecimal_group, 16) - octal += format(decimal_value, 'o') # Convert to octal + octal += format(decimal_value, "o") # Convert to octal return "0o" + octal except ValueError: return None + # Main function for user interaction def convert_number(): print("Number Conversion Tool") @@ -272,5 +296,6 @@ def convert_number(): else: print("Invalid choice. Please enter a valid option (0-12).") + if __name__ == "__main__": convert_number()