2

Im using pYcharm, Im stuck trying to make a program that requests a whole number greater than 1 as inut factors and then returns the prime numbers of the given int. Here is what i have so far:

number = int(input("Enter a positive whole number (<1):"))
f = 2
range = (1, number)
while number > 1:
    while f / number ## Does f divide by number without remainders? as in        
                           does in divide evenly?
        print(f)
        number /= f
    else:
        f += 1

The part I am stuck on, is how do I ask if f / number has a remainder or does it divide evenly?

J. Glave
  • 23
  • 2
  • I added an unnecessary line. Please ignore the range = (1, number) definition and var. – J. Glave Feb 20 '17 at 19:11
  • 1
    Possible duplicate of [How do you check whether a number is divisible by another number (Python)?](http://stackoverflow.com/questions/8002217/how-do-you-check-whether-a-number-is-divisible-by-another-number-python) – Leon Z. Feb 20 '17 at 19:11
  • Also, you may want to edit your first line. Technically a positive whole number would be `(>=1)` not `(<1)`. – Peter Feb 20 '17 at 19:13
  • I read the post and it did'nt help me. I will fix the error or >1 and <1 thank you! – J. Glave Feb 20 '17 at 19:31

1 Answers1

2

You want the modulo operator %:

>>> 5 % 3
2
>>> 15 % 5
0

Specifically a % b == 0 iff b divides a without remainder. Otherwise the remainder is returned.

Sebastian Wozny
  • 16,943
  • 7
  • 52
  • 69