So i have a challenge I'm trying to complete in python, i have to write a code to find a number after being told several properties it doesn't have. The number is between 1, 1000 and is at least two numbers, the number is prime, the number does not contain a 1 or 7, the sum of all the digits is equal to 10 or less, the first two digits add up to be odd, the second to last digit is odd, the last digit is equal to how many digits are in the number? any suggestions on a starting place for my script?
at least 2 nubers so 10 to 1000 find all primes between 10 and 10 009 find in that subset those without any 1 and 7 find those in subset where sum of nrs <= 10 etc
lol yes, but I'm unaware of how to translate that into the code. I'm pretty good at coming up with algorithms, I'm just not very good at utilizing them through a script yet
In order to see if a number has certain values - you can do: boolean prime = false; if(between 10 to 1000) { Do algorithm here to find out if prime if (prime) { Do algorithm here to isolate each digit if(none of the digits == 1 or 7) { do algorithm here to find out sum of all digits if(digit sum <= 10) { print(the number you tested for) } } } } then loop all that for the values between 10 & 1000, and you'll get a list of values that fit all those parameters... the inner print statement will only execute if all of the conditions in the if statements are met. I could make this program in java.. though sadly I can't help you with python syntax-- since the solution I propose requires you to do some advanced moves. Let me know how it goes.
Join our real-time social learning platform and learn together with your friends!