Question: Write a program in Python that defines a function called decToHex(). This function should take a single argument: a positive integer [1 mark]. If the

Write a program in Python that defines a function called decToHex(). This function should take a single argument: a positive integer [1 mark]. If the argument is within the range 0 though 15 (inclusive) your function should return a string of its value in the hexadecimal number system (you can use an If-Elif-Else statement to accomplish this) [2 marks]. If it is outside of this range, return an error message [1 mark]. E.g.,

>>> decToHex(5) "5" >>> decToHex(11) "B" >>> decToHex(17) "Error, value out of range" 

Note: Do not use the built in hex() function in your code or you will get zero for this question. Please include a number of function calls in your code to test your function beneath its definition.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!