Skip to content

Commit e2612b2

Browse files
Merge pull request #749 from 2alin/adding-digit-of-exp-python
Added last digit of exp python script
2 parents 86fbdb3 + 889bfff commit e2612b2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
def last_digit_of(a,b):
5+
""" Calculates the last digit of a^b
6+
Args:
7+
a (int): Base of a^b
8+
b (int): Exponent of a^b
9+
Returns:
10+
(int): The last digit of a^b
11+
"""
12+
13+
last_digit_a = int(str(a)[-1])
14+
15+
if b % 4 == 0:
16+
exp = 4
17+
else:
18+
exp = b % 4
19+
20+
return (last_digit_a ** exp) % 10

0 commit comments

Comments
 (0)