Question

Answer with Python. A number is cool if the sum of its digits is divisible by...

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

Homework Answers

Answer #1

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***

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C Programming Language: Given an integer N, find whether the sum of the digits calculated...
In C Programming Language: Given an integer N, find whether the sum of the digits calculated repeatedly till a single digit is obtained results in the sum of 1 or not. Display 1 if the sum of the digits of N can equal 1 else display 0. Example: For 199, Sum of digits = 1+9+9=19, 1+9=10, 1+0=1 so it should display 1 For 57, sum of digits = 5+7=12, 1+2=3 so it should display 0
A Harshad number (or a Niven number) is a number that is evenly divisible by the...
A Harshad number (or a Niven number) is a number that is evenly divisible by the sum of its digits. An example is 18 (1+8=9, 18%9 = 0). Write a function called isHarshad(num) that takes an integer as an argument and returns True if the number is a Harshad number and False if it is not. Then, use this function to create a list of all of the Harshad numbers in the first 500 natural numbers.
8. It is possible to check if an integer is divisible by 9 by summing its...
8. It is possible to check if an integer is divisible by 9 by summing its digits: if the digits add up to 9 the number is divisible by 9. For integers up to 90 only a single application of the rule is required. For larger integers, multiple applications may be required. For example, for 99, the digit sum is 18. Then, because 18 still has multiple digits we sum them again to get 9, confirming that 99 is divisible...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n,...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n, a positive integer, it returns a list of n tuples corresponding to the numbers 1 through n (both inclusive): the tuple for the number k consists of k as the first component, and exactly one of the following strings as the second: • the string 'two!' if k is divisible by 2 • the string 'three!' if k is divisible by 3 • the...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop (instead of for). • The function takes a single integer n as a parameter • The function prints a series between 1 and that parameter, and also prints its result • The result is calculated by summing the numbers between 1 and n (inclusive). If a number is divisible by 5, its square gets added to the result instead. • The function does not...
Python Programming 4th Edition: - Write a program that test and display if a number enter...
Python Programming 4th Edition: - Write a program that test and display if a number enter is divisible by 2 and/or 3. Hints: - Use the correct operation - Prompt the user to enter a number The output should look like as follows - Enter an integer: --Number is divisible by 2 and 3 --Number is divisible by either 2 or 3, but not both --Number is not divisible by either 2 or 3
Ask user to input any 5-digit positive integer value. Calculate the sum of digits of that...
Ask user to input any 5-digit positive integer value. Calculate the sum of digits of that number. Assume that the number is positive, integer, 5-digit. Example: 29107 should calculate 2+9+1+0+7 and get 19 Hint: Use the % operator to extract a digit from a number. Use loop(s) Must be in Java
Find a formula for the number of digits of 2^n. Now the textbook answer is '1+|_n*lg2_|',...
Find a formula for the number of digits of 2^n. Now the textbook answer is '1+|_n*lg2_|', the symbol used is integer floor, and lg2 is log(10)2. Question: How do I find this formula?? Show me the process of finding this formula. I know that when n=3, the number of digit is 1; when n goes pass 3, there will be 2 digits; when n goes pass 6, there will be 3 digits, and so on.
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
write a C program to find whether the given number of three digits is an integer...
write a C program to find whether the given number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is since 3**3 + 7**3 + 1**3 = 371. Output: Enter a number, or -999 to quit : 432 4**3 + 3**3 + 2**3 is not = 432 Enter a number, or -999 to quit : 371 3**3 + 7**3 + 1**3 is = 371...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT