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

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

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

如果 (integer % number) >= 1:

这就是我得到错误的地方
    print(integerr + " is divisible by " + numberr) 

else:
    
    print(integerr + " is not divisible by " + numberr)

你有两个错误。

  1. 你需要勾选if integerr % numberr == 0,因为那意味着numberr平均分为integerr;因此 integerr 可以被 numberr.

    整除
  2. input 总是 returns 一个字符串,正如 Simsteve7 提到的那样。您可以使用 int() 转换为整数,并使用 str().

    转换为字符串

下面是 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))

如果您使用的是 Python 3,则可以使用 f 弦。看起来像这样:

if (integerr % numberr) == 0:
    print(f"{integerr} is divisible by {numberr}") 
else:
    print(f"{integerr} is not divisible by {numberr}")