Given a number N, the task is to write a Python program to print the hexadecimal value of the numbers from 1 to N.
Input: 3 Output: 1 2 3 Input: 11 Output: 1 2 3 4 5 6 7 8 9 a b
- We will take the value of N as input.
- Then, we will run the for loop from 1 to N+1 and traverse each “i” through hex() function.
- Print each hexadecimal value.
Note: The hex() function is one of the built-in functions in Python3, which is used to convert an integer number into its corresponding hexadecimal form.
Below are the implementations based on the above approach:
Input: 3 1 2 3 Input: 11 1 2 3 4 5 6 7 8 9 a b
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.