Python'-Listenindizes müssen Ganzzahlen sein, nicht Tupel. "

Ich habe jetzt zwei Tage lang meinen Kopf dagegen geschlagen. Ich bin neu in Python und Programmierung, daher haben mir die anderen Beispiele für diese Art von Fehler nicht viel geholfen. Ich lese die Dokumentation für Listen und Tupel durch, habe aber nichts gefunden, was hilft. Jeder Zeiger wäre sehr dankbar. Nicht unbedingt nach der Antwort suchen, nur mehr Ressourcen zum Nachschlagen. Ich benutze Python 2.7.6. Vielen Dank

measure = raw_input("How would you like to measure the coins? Enter 1 for grams 2 for pounds.  ")

coin_args = [
["pennies", '2.5', '50.0', '.01'] 
["nickles", '5.0', '40.0', '.05']
["dimes", '2.268', '50.0', '.1']
["quarters", '5.67', '40.0', '.25']
]

if measure == 2:
    for coin, coin_weight, rolls, worth in coin_args:
        print "Enter the weight of your %s" % (coin)
        weight = float(raw_input())
        convert2grams = weight * 453.592

        num_coin = convert2grams / (float(coin_weight))
        num_roll = round(num_coin / (float(rolls)))
        amount = round(num_coin * (float(worth)), 2)

        print "You have %d %s, worth $ %d, and will need %d rolls." % (num_coin, coin, amount, num_roll)

else:
    for coin, coin_weight, rolls, worth in coin_args:
        print "Enter the weight of your %s" % (coin)
        weight = float(raw_input())

        num_coin = weight / (float(coin_weight))
        num_roll = round(num_coin / (float(rolls)))
        amount = round(num_coin * (float(worth)), 2)

        print "You have %d %s, worth $ %d, and will need %d rolls." % (num_coin, coin, amount, num_roll)

Dies ist der Stack-Trace:

File ".\coin_estimator_by_weight.py", line 5, in <module>
  ["nickles", '5.0', '40.0', '.05']
TypeError: list indices must be integers, not tuple

Antworten auf die Frage(3)

Ihre Antwort auf die Frage