+ 2
Hello Can you help me I want to build a program in Python language, type if the number given is the initial number or not
Help me,,
35 odpowiedzi
+ 9
You have to check *all* the potential divisors and check if *any* of them is indeed a divisor:
https://code.sololearn.com/cpjNU87N0gEl/?ref=app
+ 6
Oh, primes are a different story -- you have to check if there is a number in a range from 2 to the square root of x, by which x divides without a remainder.
x % this_number = 0
+ 6
Amina Alsraya If I understand it correctly, you want to determine if a number is prime or not.
Prime numbers are such that can be divided *only* by itself and 1.
Is that what you want?
+ 5
D'lite You can learn more on the basic integer array implementation in this thread:
https://stackoverflow.com/questions/306313/is-operator-behaves-unexpectedly-with-integers
Amina Alsraya Sorry for a bit off-topic :)
+ 5
Amina Alsraya So take the code above and study it -- it checks if there is *any* divisor for the number that divides without a remainder. If there is *any* such number found in the iteration, the whole expression gets the True value, so the number is *not* a prime. Just in order for the function to be intuitively understood, I negated it, so it really answers the question is_prime ;)
+ 5
Amina Alsraya The thing about the primes is that there is no other way to determine if it is prime indeed than iteratively looking for its divisors other than 1 and itself.
There are some ways to speed the process up, but in the end there is always some kind of iteration to be done.
We use primes mainly in security and encryption because of this very property that they can not be factorized (or "calculated") in any way other than by this iterative process.
+ 4
Amina Alsraya What do you want the program to do?
+ 4
1. Take the input
2. Convert it to int
3. Check if it is equal to the initial number
4. Print out the result
Which part seems to be the problem?
+ 4
In its simplest form it could be something like this:
https://code.sololearn.com/cYk7I7O0u2Tt/?ref=app
+ 4
D'lite It won't work with "is" for numbers greater than 256 ;)
+ 2
number = 857;
inp = int(input("Enter your number"))
if inp == number:
print("Correct !")
else:
print("Wrong !")
+ 2
D'lite Try it ;)
+ 2
Amina Alsraya
Here's my code
https://code.sololearn.com/cS3ZiAWYHGo3/?ref=app
+ 1
Tall
+ 1
What did you know about initial number
0
To print if the number was initial number
0
Help me
0
The program
0
How
0
Kuba SiekierzyĆski Why wouldn't it?