DESCRIPTION: The below code converts Octal to Decimal, Binary, Hexadecimal.

The user has to enter a choice, and then the octal value for converting it into its respective

choice.

Enter 1 for Octal to Decimal conversion

Enter 2 for Octal to Binary conversion

Enter 3 for Octal to Hexadecimal conversion

#The class is converting octal numbers
class Octal():
#Constructor takes the Choice
def __init__(self, choice):
self.choice = choice
def octal_conversion(self):
#If entered choice is 1, 2, or 3
if(self.choice >=1 and self.choice <= 3):
#Enter octal number
octal = **input**("Enter number in octal format: ")
#Octal to Decimal
if self.choice == 1:
decimal = str(int(octal,8))
print(octal, "in Decimal is ", decimal)
#Octal to Binary
elif self.choice == 2:
decimal = str(int(octal, 8))
decm = int(decimal)
print(octal, "in Binary is ", bin(decm))
#Octal to Hexadecimal
elif self.choice == 3:
decimal = str(int(octal, 8))
decm = int(decimal)
print(octal, "in HexaDecimal is ", hex(decm))
#If user wants to exit
elif self.choice == 4:
exit()
#User enters an invalid choice
else:
print("Invalid Entry!!")
def main():
#Following choices can be entered
#for converting Octal to Decimal, Binary, Hexadecimal
print("Type")
print("1 for Octal to Decimal")
print("2 for Octal to Binary")
print("3 for Octal to Hexadecimal")
print("4 for exit")
#Enter a valid choice
choice = int(**input**("Enter your Choice: "))
#Object created for the class Octal
obj_Octal = Octal(choice)
obj_Octal.octal_conversion()
if __name__ == "__main__":
main()
OUTPUT:
Test case 1:
Type
1 for Octal to Decimal
2 for Octal to Binary
3 for Octal to Hexadecimal
4 for exit
Enter your Choice: 1
Enter number in octal format: 2567
2567 in Decimal is 1399
Test case 2:
Type
1 for Octal to Decimal
2 for Octal to Binary
3 for Octal to Hexadecimal
4 for exit
Enter your Choice: 2
Enter number in octal format: 2567
2567 in Binary is 0b10101110111
Test case 3:
Type
1 for Octal to Decimal
2 for Octal to Binary
3 for Octal to Hexadecimal
4 for exit
Enter your Choice: 3
Enter number in octal format: 2567
2567 in Hexadecimal is 0x577
Test case 4:
Type
1 for Octal to Decimal
2 for Octal to Binary
3 for Octal to Hexadecimal
4 for exit
Enter your Choice: 7
Invalid Entry!!

## Comments