I am trying to run a simple program to check a number to see if it is prime or not. I am having the user provide the number to check. But, I keep getting the following error when I run the program:
Traceback (most recent call last):
File "HelloWorld.py", line 6, in <module>
if num % test == 0 and num != test:
TypeError: not all arguments converted during string formatting
The following is my code:
num = input('Please choose a number between 2 and 9:')
prime = True
for test in range(2,10):
if num % test == 0 and num != test:
print(num,'equals',test, 'x', num/test)
prime = False
if prime:
print(num, 'is a prime number!')
else:
print(num, 'is not a prime number!')
I am using Python 3. Please let me know what I am doing wrong and how to understand why my program isn't running properly. Thanks in advance!
input()always returns text so you have to convertnumintoint- ie.num = int(num)