Skip to content

Commit

Permalink
Test code (shhossain#719)
Browse files Browse the repository at this point in the history
* fix test_code 2

* test 2

* fix 2
  • Loading branch information
shhossain authored Oct 31, 2023
1 parent c10ab16 commit c8aaab7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 22 additions & 2 deletions Number System/Conversion_In_Python1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Author: SK Jiyad
Github: https://github.com/ZRX-SIGMA
Date: 2021-10-09
Expand Down Expand Up @@ -26,44 +26,57 @@
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):
try:
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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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")
Expand Down Expand Up @@ -178,5 +197,6 @@ def convert_number():
else:
print("Invalid choice. Please enter a valid option (0-12).")


if __name__ == "__main__":
convert_number()
69 changes: 47 additions & 22 deletions Number System/Conversion_In_Python2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Author: SK Jiyad
Github: https://github.com/ZRX-SIGMA
Date: 2023-10-07
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -65,20 +68,21 @@ 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:
if binary.startswith("0b"):
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
Expand All @@ -93,119 +97,139 @@ 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:
if hexadecimal.startswith("0x"):
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:
if binary.startswith("0b"):
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:
if binary.startswith("0b"):
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:
if octal.startswith("0o"):
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:
if octal.startswith("0o"):
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:
if hexadecimal.startswith("0x"):
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:
if hexadecimal.startswith("0x"):
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")
Expand Down Expand Up @@ -272,5 +296,6 @@ def convert_number():
else:
print("Invalid choice. Please enter a valid option (0-12).")


if __name__ == "__main__":
convert_number()

0 comments on commit c8aaab7

Please sign in to comment.