226k views
5 votes
Write a function named last_digit that returns the last digit of an integer. For example, last_digit(3572) should return 2. It should work for negative numbers as well; last_digit(-947) should return 7.

User Akhtar
by
8.1k points

1 Answer

2 votes

def last_digit(num):

num = str(num)

return int(num[-1])

print(last_digit(-947))

I hope this helps!

User Brooke
by
8.5k points

Related questions

asked Aug 7, 2019 24.6k views
ParveenArora asked Aug 7, 2019
by ParveenArora
8.0k points
2 answers
0 votes
24.6k views
asked Oct 27, 2019 188k views
Helpful asked Oct 27, 2019
by Helpful
8.2k points
1 answer
0 votes
188k views
asked Sep 11, 2019 199k views
Ramarao Amara asked Sep 11, 2019
by Ramarao Amara
8.3k points
2 answers
3 votes
199k views