Find unit digit of x raised to power y | Python3 code to find the unit digit of x raised to power y . ; Find unit digit ; Get last digit of x ; Last cyclic modular value ; Here we simply return the unit digit or the power of a number ; Driver code ; Get unit digit number here we pass the unit digit of x and the last cyclicity number that is y % 4
import math NEW_LINE def unitnumber ( x , y ) : NEW_LINE INDENT x = x % 10 NEW_LINE if y != 0 : NEW_LINE INDENT y = y % 4 + 4 NEW_LINE DEDENT return ( ( ( int ) ( math . pow ( x , y ) ) ) % 10 ) NEW_LINE DEDENT x = 133 ; y = 5 NEW_LINE print ( unitnumber ( x , y ) ) NEW_LINE