목록을 반복하여 파일에 기록 된 목록 내의 요소와 일치하는 항목을 찾고 목록의 요소에 지정된 총 가격을 추가 할 수 있기를 원합니다. 여기에 내가 지금까지 가지고있는 것이 있습니다 - 단지 요소의 일치를 찾고 추가하는 방법을 모르십시오. - 예 : 귀하의 경비 명단에는 "정크 푸드"라고 불리는 여러 항목이 포함될 수 있으며 각각에 대해 비용에 해당하는 priceList 항목이 있습니다.목록을 반복하여 요소를 찾고 해당 요소를 기반으로 한 총 가격을 추가 하시겠습니까?
def expensesManager():
filePath=pickAFile()
file=open(filePath,"w")
numExpenses=requestInteger("How many weekly expenses do you currently have?")
expensePriceList=[None]*numExpenses
expenseNameList=[None]*numExpenses
index=0
total=0
while(index<numExpenses):
expenseNameList[index]=requestString("Name of Expense "+str(index+1))
expensePriceList[index]=requestNumber("Price of "+ str(expenseNameList[index].capitalize())+" per week")
lineList=(expenseNameList[index].capitalize()+" "+str(expensePriceList[index])+"\n")
total=expensePriceList[index]
print "Your total expenditure on "+str(expenseNameList[index]).capitalize()+ " per month is $"+str((total)*4)
file.writelines(lineList)
index=index+1
file.close()
반복 목록에있는 샘플을 제공 할 수 있습니까? –
@WillP expenseNameList는 루프하려는 목록입니다. 따라서 requestString 함수에 두 번 "청구서"를 입력하면이 값을 두 번 입력하고 requestNumber 함수에 입력하는 두 가지 금액의 "청구서"를 합산 한 것으로 인식합니다. – sdillon87
그리고 샘플에 의해 Will P는 데이터의 이름이 아닌 샘플 데이터를 의미합니다. – thatrockbottomprogrammer