To convert octal to hexadecimal number in python, you have to ask from user to enter a number in octal format and start converting the given number into hexadecimal format just by using the function hex() as shown here in the program given below.
Following python program ask from user to enter a number in octal format to convert the number in hexadecimal number system:
# Python Program - Convert Octal to Hexadecimal print("Enter 'x' for exit."); octal = input("Enter a number in Octal Format: "); if octal == 'x': exit(); else: dec = str(int(octal, 8)); decm = int(dec); print(octal,"in Hexadecimal =",hex(decm));
Here is the sample run of the above Python program demonstrating how to convert a number from octal number system to hexadecimal number system:
Now enter a number in octal and press enter to find out that what will be the same number in hexadecimal format as shown here in below screenshot:
Below is the same program with run on python shell:
You may also like to learn or practice the same program in other popular programming languages: