What two whole, positive numbers that have a one-digit answer when multiplied and a two-digit answer when added? riddle source: http://riddles.com/

How to?

We need to declare 2 variable sum and mult

:

sum

is to check the sum of the 2 digits.

mult is to check the multiplication of the 1 digit.

And both should be assigned as 0.

sum = 0
mult = 0

Now we need 2 for loops to iterate through the needed numbers The numbers should be between 1 and 9, beacuse their multiplication should be only 1 digit. 1-Any number multiplied by 0 will result 0

2-Any number less than 10 multiplied by 10 or a number greater than 10 will result to number of 2 digits

for x in range(1, 10):
    for y in range(1, 10):
        sum = x + y
        mult = x * y
        if(sum >= 10):
            if(mult < 10):
                print(str(x) + " and " + str(y))
        break

And finally we need to break the iteration at the end of the second loop to avoid iterating through the same numbers twice.

Answer


 > 9 and 1

This post is also available on DEV.