96.5k views
10 votes
You have the following code:

----------------------------------------------------------------------------------------------
fruit_list = ["strawberries", "bananas", "apples", "grapes"]
total_cost = 0
for fruit in fruit_list:
if fruit in ["apples","bananas"]:
total_cost += 3
elif fruit == "cantaloupe":
total_cost += 5
elif fruit in ["raspberries","strawberries","grapes"]:
total_cost += 4
-------------------------------------------------------------------------------------------------

What will be the value of total_cost?

A.13
B.14
C.15
D.7

User Syperus
by
5.2k points

1 Answer

6 votes

Answer:

7

Step-by-step explanation:

We already have the functions that tells us how much to add. If you add all this, you will get 12. HOWEVER because cantaloupe is in the list, the computer does not count that. So if we add that again without 5(how much the cantaloupe costs), we get 7.

User Handras
by
4.9k points