+ 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,,

25th Nov 2018, 5:18 PM
Amina Alsraya
Amina Alsraya - avatar
35 Answers
+ 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
25th Nov 2018, 6:00 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 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
25th Nov 2018, 5:50 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 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?
25th Nov 2018, 6:30 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 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 :)
25th Nov 2018, 5:43 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 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 ;)
25th Nov 2018, 7:22 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 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.
26th Nov 2018, 1:59 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 4
Amina Alsraya What do you want the program to do?
25th Nov 2018, 5:22 PM
Dlite
Dlite - avatar
+ 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?
25th Nov 2018, 5:26 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 4
In its simplest form it could be something like this: https://code.sololearn.com/cYk7I7O0u2Tt/?ref=app
25th Nov 2018, 5:32 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 4
D'lite It won't work with "is" for numbers greater than 256 ;)
25th Nov 2018, 5:33 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 2
number = 857; inp = int(input("Enter your number")) if inp == number: print("Correct !") else: print("Wrong !")
25th Nov 2018, 5:30 PM
Dlite
Dlite - avatar
+ 2
D'lite Try it ;)
25th Nov 2018, 5:35 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
25th Nov 2018, 5:37 PM
Dlite
Dlite - avatar
+ 1
Tall
25th Nov 2018, 5:41 PM
Amina Alsraya
Amina Alsraya - avatar
+ 1
What did you know about initial number
26th Nov 2018, 2:43 PM
Kelvin Maheri
0
To print if the number was initial number
25th Nov 2018, 5:23 PM
Amina Alsraya
Amina Alsraya - avatar
0
Help me
25th Nov 2018, 5:23 PM
Amina Alsraya
Amina Alsraya - avatar
0
The program
25th Nov 2018, 5:27 PM
Amina Alsraya
Amina Alsraya - avatar
0
How
25th Nov 2018, 5:27 PM
Amina Alsraya
Amina Alsraya - avatar
0
Kuba SiekierzyƄski Why wouldn't it?
25th Nov 2018, 5:34 PM
Dlite
Dlite - avatar