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.
input
always returns a string, as Simsteve7 mentioned. You can convert to an integer usingint()
, and convert to a string usingstr()
.You need to check
if integerr % numberr == 0
, because that means thatnumberr
divides intointegerr
evenly; thusintegerr
is divisible bynumberr
.
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}")