Skip to content
Advertisement

Line 7 Type error: Not all arguments converted during string formatting if (integerr % numberr) >= 1: [duplicate]

name = input("Say your name: ")
integerr = input(name + " pick an integer ")
numberr = input(name + " pick another integer ")

This is where I get my error

if (integerr % numberr) >= 1: 
    print(integerr + " is divisible by " + numberr) 
else:
    print(integerr + " is not divisible by " + numberr)

Advertisement

Answer

You have two mistakes.

  1. input always returns a string, as Simsteve7 mentioned. You can convert to an integer using int(), and convert to a string using str().

  2. You need to check if integerr % numberr == 0, because that means that numberr divides into integerr evenly; thus integerr is divisible by numberr.

Below is a solution for Python 2:

name = input("Say your name: ")
integerr = int(input(name + " pick an integer "))
numberr = int(input(name + " pick another integer "))
if (integerr % numberr) == 0:
    print(str(integerr) + " is divisible by " + str(numberr)) 
else:
    print(str(integerr) + " is not divisible by " + str(numberr))

If you’re using Python 3, you can use f-strings. That would look like this:

if (integerr % numberr) == 0:
    print(f"{integerr} is divisible by {numberr}") 
else:
    print(f"{integerr} is not divisible by {numberr}") 
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement