【发布时间】:2013-03-07 22:41:29
【问题描述】:
这段代码出错
print('type a whole number:')
n = input()
if n % 2 == 1:
print('Odd');
else:
print('Even');
我假设我必须对 if 语句中的变量 n 做一些特别的事情?我是 Python 初学者。
【问题讨论】:
-
Python 2.x 或 Python 3.x ???
-
@Schoolboy 肯定是py3.x,因为
input()在py2.x中返回一个整数,而错误not all arguments converted during string formatting明确表明input()在这里返回了一个字符串。