我试图通过模运算符确定输入;但是,当我运行此代码时,我得到一个TypeError
number = input(enter a number)
if(number%2 == 0):
print( 'obviously',number, 'is even') #conditional that prints the number and a statment
else:
print( 'obviously', number, 'is odd');
我的问题是:导致TypeError
答案 0 :(得分:2)
在Python 3中,input
返回一个字符串。您不能对字符串执行模数。所以你需要把它变成一个整数。
number = int(input('Enter a number:'))