Question: A decent number is a positive integer that satisfies these three rules: 1) the number only consists of 3s and 5s, 2) the number of

A decent number is a positive integer that satisfies these three rules:

1) the number only consists of 3s and 5s, 2) the number of 3s is divisible by 5, and 3) the number of 5s is divisible by 3.

Write a Python function called common_decency that takes a positive integer argument NN and returns a Boolean (True/False) representing whether or not the input integer is a decent number. For example:

common_decency(2) = False, because 2 is not a decent number (it fails on Rule 1, but passes on Rules 2 and 3)

common_decency(555) = True, because there are only 3s and 5s (passes Rule 1), the number of 3s (0) is divisible by 5 (since there exists an integer kksuch that 0=5k0=5k, namely k=0k=0, so it passes Rule 2), and the number of 5s (3) is divisible by 3

common_decency(53535) = False, because the number of 3s is not divisible by 5

Potentially handy Python methods:

A) You may find the Python str() and int() methods handy, which convert numbers to strings and strings to integers, respectively.

B) It is possible to iterate in a for loop over the characters in a string. For example, try out the following code in your own Python IDE:

for letter in 'cats': print(letter)

Ex:

Test Result
print(common_decency(2))
False
print(common_decency(555))
True
print(common_decency(53535))
False

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!