6.5k views
0 votes
Write a Python program that can convert an integer between 0 and 15 into hexnumber (including 0 and 15). The user enters an integer from the console,and the program displays the corresponding hex number. If the user enters an integer out of range, the program displays a warning message about the invalid input.

User Fumiko
by
3.4k points

1 Answer

5 votes

Answer:

number = int(input("Enter an integer: "))

if 0 <= number <= 15:

print(str(number) + " in hexadecimal is: " + str(hex(number)))

else:

print("Invalid input!")

Step-by-step explanation:

Ask the user to enter an integer and set it to the number

Check if the number is between 0 and 15. If it is, then convert the number into hexadecimal number using hex method and print it. Otherwise, print a warning message.

User Ekgren
by
3.7k points