vendredi 6 mars 2020

Is there a way to add up amount depending on what is in a certain position on a text file?

I have tried

totalValue = 0 bagsChecked = 0

for x in range(len(volunteerList)):
    record = volunteerList[x]

    if record[1] == "1 pence":
        amount = 1.00
    elif record[1] == "2 pence":
        amount = 1.00
    elif record[1] == "5 pence":
        amount = 5.00
    elif record[1] == "10 pence":
        amount = 5.00
    elif record[1] == "20 pence":
        amount = 10.00
    elif record[1] == "50 pence":

        amount = 10.00
    elif record[1] == "1 pound":
        amount = 20.00
    else:
        amount = 20.00

    totalValue = totalValue + amount
    bagsChecked = bagsChecked + 1

    print("Bags checked: ",bagsChecked)
    print("Total Value: ",totalValue)'''

Is there a way that I can fix this so that it displays an accurate number of bags checked and total value.

Aucun commentaire:

Enregistrer un commentaire