Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Kevork Keheian
Kevork Keheian

Posted on • Edited on

     

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 variablesum andmult:

  • sum is to check thesum of the 2 digits.
  • mult is to check themultiplication of the 1 digit.

And both should be assigned as 0.

sum=0mult=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

forxinrange(1,10):foryinrange(1,10):sum=x+ymult=x*yif(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

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Data 💚
  • Location
    Lebanon
  • Work
    Data Analyst at Spinneys Lebanon
  • Joined

More fromKevork Keheian

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp