DEV Community

Kevork Keheian
Kevork Keheian

Posted on • Edited on

1 3

Computational Thinking - Riddle 1

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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay