Доброго. Вот решил изучить Питон, благо указанный ресурс в этом не плохо помогает, прошел больше половины заданий, и тут вперся в стенку( и вся проблема в том что я не понимаю что от меня хотят.. в английском я не особо силен..
Собственно текст задания:
Цитата | Making a Purchase Good! Now you're going to need to know how much you’re paying for all of the items on your grocery list.
Remember how to compute a rolling sum? If not, here's a reminder: total += price is the same as total = total + price. Evaluating the right hand side grabs the values of those variables, adds those values and then stores it back into the variable total.
INSTRUCTIONS Write a function compute_bill that takes a parameter food as input and computes your bill by looping through your food list and summing the costs of each item in the list. For now, go ahead and ignore whether or not the item you're billing for is in stock.
Hint First you will need a variable total with an initial value of zero. While looping though your list, add the price of every object in the list into total.
|
а вот что я делаю
Код | groceries = ["banana", "orange", "apple"]
stock = { "banana": 6, "apple": 0, "orange": 32, "pear": 15 } prices = { "banana": 4, "apple": 2, "orange": 1.5, "pear": 3 }
def compute_bill(food): total=0 for item in food: if stock[item]<>0: total+=prices[item] return total
print compute_bill(groceries)
|
в итоге получаю рабочий код и верный ответ вроде бы), но ошибку по заданию, вида:
Цитата | Oops, try again! You code does not seem to work when [u'apple'] is used as input--it returns 0 instead of 2.
|
Что я делаю не так( |