Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 4 - Selections - Programming Exercises - Page 130: 4.33

Answer

code

Work Step by Step

# 4.33 (Decimal to hex) Write a program that prompts the user to enter an integer # between 0 and 15 and displays its corresponding hex number. dec = int(input("Enter a decimal value (0 to 15): ")) if 0 <= dec < 10: print("The hex value is", dec) elif dec == 10: print("The hex value is A") elif dec == 11: print("The hex value is B") elif dec == 12: print("The hex value is C") elif dec == 13: print("The hex value is D") elif dec == 14: print("The hex value is E") elif dec == 15: print("The hex value is F") else: print("Invalid input")
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.