我是编码新手,我的程序有问题。我必须从文件中获取销售信息并以某种格式打印出来。这是代码:
#Looping program to read file per line
for line in lines:
# Formatting line to read later
line = line.strip().split(',')
year = line[0]
year = int(year)
month = line[1]
month = int(month)
day = line[2]
day = int(day)
linePoint = date(year, month, day)
cost = line[3]
cost = float(cost)
#Finding the lines within the start and end date
if (linePoint >= startDate) and (linePoint <= endDate):
printcost = (cost / 100)
printcost = int(printcost)
print "%s.%s.%s" % (startYear, startMonth, startDay)
print "0%s:" % printNum, "*" * printcost
newcost = newcost + cost
printNum += 1
当我使用%s.%s.%s
它在销售上方打印日期时,我希望它每月在另一个打印报表上方打印一次,并且能够在一个月结束后增加它。同样在print "0%s:" % printNum, "*" * printcost
声明中,我希望它只在前 9 天打印零。
本质上我的问题是我如何在 Python 中运行某些东西一定次数,但次数取决于用户并与日期相关,为了做到这一点,计算机需要能够识别日期。抱歉含糊不清。