【发布时间】:2016-10-17 19:09:58
【问题描述】:
def process_cars(text_file):
total_cmpg = 0
for line in text_file:
if((line % 2) == 0):
city_mpg = (line[52:54])
print(city_mpg)
city_mpg = int(city_mpg)
total_cmpg += city_mpg
print ("Total miles per gallon in the city:", total_cmpg)
错误出现在 if((line % 2) == 0): 我已经搜索了具有相同错误的其他问题,但没有一个可以解决问题。错误是:在字符串格式化期间并非所有参数都转换了。我想修改线条的位置。例如,如果是第三行,则为 2 % 2。
【问题讨论】:
-
你想用
line % 2做什么你想修改线路中的数字吗? -
我正在尝试调整线条的位置。如果是第三行,那么 2 % 2 @MooingRawr
标签: python python-3.x