0
print("Enter the number you want to test")
Num1 = input("Enter your number here:")
if (Num1%1 == '0' and Num1%Num1 == '0'):
    print ("This number is prime number")
else:
    print("This number is nor prime number")

This is failing with an error of TypeError: not all arguments converted during string formatting. What is the cause and how can I fix it?

Vikash Pandey
  • 5,407
  • 6
  • 41
  • 42
  • 4
    While others are answering what the error means and how to fix it, I'll point out that your algorithm for figuring out whether a number is prime is flawed; the if statement will always return true for any integer. – Reti43 Jan 16 '16 at 22:21
  • What's the point of `Num1 % 1`? All integers are equal to 0 modulo 1. – Barmar Jan 16 '16 at 22:26
  • Possible duplicate of [How can I read inputs as integers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-integers) – tripleee Mar 11 '18 at 10:36

1 Answers1

1

input returns a string , you should convert it to int:

Num1 = int(input("Enter your name here:"))

And if parts changed to :

if (Num1%1 == 0 and Num1%Num1 == 0):

However your code logic for realize that a number is prime or not is not correct , you should check that number has a factor or not , you should write a for loop through it's lower numbers and realize that.it's simple but I think it's better for you that write it yourself.

ᴀʀᴍᴀɴ
  • 4,443
  • 8
  • 37
  • 57