Why did nothing print to the screen when I pressed Run?


Why did nothing print to the screen when I pressed Run?


To see your results be sure to call your compute_bill() function in a print statement and pass it the shopping_list list variable as an argument. Like this: print compute_bill(shopping_list).


How do we compute for the different number of fruits that we want the compute_ bill function to perform. Currently it is returning the answer 5.5 for the parameter (shopping _list) as it is considering only a single amount for each fruit. When I try to convert (shopping_list) to a dictionary and add different values for the keys(fruits), it returns the same value 5.5 ?

shopping_list represents a list of products the customer wants to buy. The customer can’t determine the price, the prices are fetched from prices dictionary. So if prices of products need to change, prices needs to be changed

we can pass different lists to compute_bill, which represents customers. for example:

print compute_bill(["banana", "orange", "apple", "banana", "orange", "apple"])

Thank you for the reply. Besides the method that you have given above, what would be the other methods, if we were to calculate the total bill for the various quantities of each fruit that the customer would buy ?

at the moment, nothing. We need to provide the fruit multiple times as string, or modify the code.

what you could also do, would be adding a third dictionary saying the quantity you want and then setting the total to be price * quantity, but in this case you are modifying the code.

1 Like
shopping_list = ["banana", "orange", "apple"]

stock = {
  "banana": 6,
  "apple": 0,
  "orange": 32,
  "pear": 15
prices = {
  "banana": 4,
  "apple": 2,
  "orange": 1.5,
  "pear": 3

# Write your code below!
def compute_bill(shopping_list):
    total = 0
    for item in shopping_list:
        if stock[item]>0:
            total += prices[item]
            stock[item] -= 1
    return total
    print compute_bill(shopping_list)

i was able to pass the page, but still nothing printed on the screen

Did you ever call the function compute_bill()?

the last line of my code is “print compute_bill(shopping_list)” if that’s what you are asking.

Well, looking at the lesson, page 12 wants only the function, not the calling statement; your function passes with the calling statement commented out. Then, page 13 ( the final page) does ask for the calling statement, which does print to the screen, as expected.