Answer with Python. A number is cool if the sum of its digits is divisible by 5. Given an integer n, return the nth cool number.
def nthCool(n):
nthCool(1) = 5
nthCool(2) = 14
nthCool(3) = 19
code :
output :
raw_code :
def nthCool(n):
count = 0
cool = 0
i = 1
while(count<=n):
summ = 0
#summing individual digits
for s in str(i):
summ += int(s)
if(summ%5==0 ):
count += 1
if(count == n): #checking for nth digit
return i
i += 1
#calling our function
print(nthCool(1))
print(nthCool(2))
print(nthCool(3))
**do comment for queries and rate me up***
Get Answers For Free
Most questions answered within 1 hours.