Computer Science, asked by krisha1402, 10 months ago

write a function that takes a positive integer and returns the one's position digits of the integer. If the ones position digit is zero then the function should return None . (Python)

Answers

Answered by AbbasMaths
15

Answer:

Hey , to play with digits , you should be aware of modulos operator .Its symbol is ( % ). It is used to find out remainder of a division . For example , when we divide 6 by 4 , then remainder is 2 and quotient is 1. So , we can write it as , 6 % 4 = 2.

Now coming to code , you can write as follows-

x = int ( input( ) )

print(x % 10)

Suppose you entered the number 23.

Then you are going to gain its ones digit i.e. 3.

Note- This is valid for only numbers bigger than 10.

You can use the integer 5 for this also for modulo operation.

Hence , you got your ones digit.

Now , coming to second part , if ones digit is zero , it should return none. So,

Complete code will be :

x = int ( input( ) )

y = x % 10

print(y)

if y < 1:

print("none")

Hope so it helps,

The main concept is to use modulo operator correctly.

Attachments:
Similar questions