Question: part a please [10] 4. (a) Write a Python or MATLAB function that when given a number between 0 and 9 outputs a character string
part a please
[10] 4. (a) Write a Python or MATLAB function that when given a number between 0 and 9 outputs a character string for the word representation of that number. For example, an input of 1 should return the character string 'one', an input of 2 should return two' etc. Your function should check whether the number inputted is an integer between 0 and 9 and print a suitable error message if not. (b) Write a Python or MATLAB program that defines an integer variable x which is equal to your ID number and prints a string of words representing each digit of that number. For example, if your student ID number is 21012345 then your program should output [15] two, one, zero, one, two, three, four, five, Hint: you might find the following commands for converting between numbers and strings useful for answering part (b): Function Python MATLAB convert a number to a string str(x) string(x) convert a string to an integer int(string) str2num(string)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
