【发布时间】:2015-03-30 14:58:19
【问题描述】:
def main():
spiral = open('spiral.txt', 'r') # open input text file
dim = spiral.readline() # read first line of text
print(dim)
if (dim % 2 == 0): # check to see if even
dim += 1 # make odd
我知道这可能很明显,但我不知道发生了什么。我正在阅读一个只有一个数字的文件并检查它是否是偶数。我知道它被正确读取,因为当我调用它来打印dim 时,它会打印出10。但后来它说:
TypeError:字符串格式化期间并非所有参数都转换
对于我正在测试的行,以查看 dim 是否均匀。我确定这是基本的,但我无法弄清楚。
【问题讨论】:
标签: python python-3.x