computer science with python...grade12
Anybody plss give the program code (answer)...
NO SPAM..
IF THE ANSWER IS INAPPROPRIATE, UR ANSWER WILL BE REPORTED....
PLSS HELP ME FRIENDS...
Answers
Answer:
Here you go... (in Python)
Explanation:
def getOnes(num):
num_list = list(str(num))
return int(num_list[2])
Explanation:
As simple as that...
First we create a function which takes a number as the input. Note that the inputted number must be an integer and not a string. Next, inside the function, the number is converted into a list of its digits. For example, if the number 345 is entered into the function, then the list will be:
['3', '4', '5']
Now, all that is left is to access the third digit(which is the ones digit). This can be done by
num_list[2]
Note that in Python, array indexes always start from 0 and that is the reason instead of 3, we have 2 in the square brackets [ ].
Note that this code works only for 3-digit numbers.
For numbers of other digits, we will first have to find the number of digits and then access only the last digit. Hope you understood, and if you did, then please don't forget to star it.