Expand|Select|Wrap|Line Numbers
- # Find the prime numbers
- # This is a user input program that lets you decide if a number is a prime or not
- import math
- num = int(raw_input("Please enter a number: "))
- #num = int(math.sqrt(num))
- for i in range(2,math.sqrt(num)):
- #for i in range(2,num/2):
- prime = num%i
- if prime == 0.0:
- print "It is not a prime"
- break
- else:
- print "It is a prime"
- break
Warning (from warnings module):
File "/Users/trillian/Documents/programs:documents/python programs/Chapter 4/prime", line 10
for i in range(2,math.sqrt(num)):
DeprecationWarning: integer argument expected, got float
Now does range takes ONLY integers or can it take float as well?
2) If you test my program it works well, but it gives "9" as a prime. :-(
3) How do I loop such that I do not need to use "break" statement and still it tells me if a number is a prime or not?
Thanks a lot.