For example, firstDigit(1729) is 1, lastDigit(1729) is 9, and digits(1729) is 4.
keep it simple python
def firstDigit(n): result = 0 while n != 0: result = n % 10 n = n // 10 return result def lastDigit(n): return n%10 def digits(n): count = 0 while n!=0: n = n//10 count += 1 return count def main(): print(firstDigit(1729)) print(lastDigit(1729)) print(digits(1729)) main()
Get Answers For Free
Most questions answered within 1 hours.