In Python only. Write a program that prompts the user to enter a hex character and displays its corresponding decimal integer.
Python code:
#accepting input
hex_num=input()
#checking if it is a number
if(hex_num>='0' and hex_num<='9'):
#printing that number
print(hex_num)
#checking if it is a or A
elif(hex_num=='a' or hex_num=='A'):
#printing its corresponding number
print(10)
#checking if it is b or B
elif(hex_num=='b' or hex_num=='B'):
#printing its corresponding number
print(11)
#checking if it is c or C
elif(hex_num=='c' or hex_num=='C'):
#printing its corresponding number
print(12)
#checking if it is d or D
elif(hex_num=='d' or hex_num=='D'):
#printing its corresponding number
print(13)
#checking if it is e or E
elif(hex_num=='e' or hex_num=='E'):
#printing its corresponding number
print(14)
#checking if it is f or F
elif(hex_num=='f' or hex_num=='F'):
#printing its corresponding number
print(15)
Screenshot:
Input and Output:
Get Answers For Free
Most questions answered within 1 hours.