Challenge 5 Megathread

For any and all questions relating to challenge 5. :point_down:

For a tutorial on how to use Jupyter Notebook, we put together this video:

Still have questions? Read all the FAQs here.

Is the hint reversed? The challenge is to find out which items cost over 10% more at the nearby (country?) store but the hint’s formula is to find out which items cost over 10% more at the city store.


The wording is a bit confusing… which store is supposed to be the more expensive one? The city or the country? Is the ‘small town’ store considered ‘country’??


Ha, I was wondering why neither my “don’t buy” nor my “do buy” list matched any of the answers. That’s what I get for sleepily following the hint without question!

ETA: For comparison, the hint lists the formula

C=(CityPrice−CountryPrice)/CountryPrice > 0.1

The solution uses the formula

(country_price - city_price)/city_price > 0.1

(Also noticed that the Explanation/Solution seems to be incorrectly using variables from the previous challenge, such as wholesale_price_list.)


Yes. I checked over my solution several times and it does not match any of the multiple choice answers.


I assumed that the “town” mentioned in the story is a small town in the country, and the city would be farther to go. So only if the country shops are at least 10% more expensive would you add an item to the city shopping list or in other words avoid them in the country shop.

Also rather than use the hint equation which didn’t give me lists that matched any answer, I stuck with my first pass one which was something like: if city < country*1.10.


I got the answer only by messing around and swapping my lists till they matched - isn’t the city and country backwards? I admit that I assumed that she lived in the country and not the city, since the question just said “town”. It’s kind of frustrating how ambiguous it is - I hope it’s intentional because if not…

But anyways, can anyone help me understand why a condition like country_price > 1.10 * city_price doesn’t end up with the same result? It gave me a different list but in my mind it should be the same.

I’m trying to justify it with some math from the hint formula:
(country_price - city_price) / city_price > 0.1
(country_price / city_price) - (city_price / city_price) > 0.1
(country_price / city_price) - (1) > 0.1
country_price / city_price > 0.1 + 1
country_price > 1.10 * city_price


Only thing that confused me was i didnt catch that i was looking for the more expensive items and not the less expensive items. Funny how i fill in the gaps with how you would do things in real life… I’d be writing a list of things i wanna buy… Not the things i that are too expensive. Anyways once i got over that i just edited my code to something that would present a clear answer. In a weird way its backwards because of that… Interested in optimization feedback though.


for (i) in range(len(cleaningsupplies_list)):
if country_price[i] <= 1.1*city_price[i]:
print(cleaningsupplies_list[i], “too expensive”)


What worked for me was to calculate which items cost 10% more in the country store than the city store. In terms of the wording of the problem, this would mean that the country store was the nearby store. The hint did not work for me, instead I used (country-city)/city > 0.1.

1 Like

AH. I’m not great at math so just assumed that the hint given in the formula was what we were supposed to use. Then ran my code way too long before looking at the message board to find out why the code was working but none of my answers were in the multiple choice. Wonder if this was a typo or intentional, to give us the formula but not the exact equation…

1 Like

the hint equation is wrong, was that intentional?


Video Solution:

A good challenge that utilities concepts from previous days.


The wording is quite confusing. It would have been more helpful it was more explicit as to knowing if it is city or country pricing should be more expensive. Can’t remember where Dot moved to as per previous challenges.


So, I wasn’t sure which store was the closest store, and after making an assumption as to which prices would be more expensive, I generated the list of >10% more expensive items, but they didn’t match the choices. I added lines to also calculate the list of >10% more expensive items from other store, and there was a match. Hooray.

I didn’t internalize the initial narrative, but I gather from the country barn/cabin in the header image that Dot has moved to the country.

1 Like

Same here - but I didn’t look at the hint till after I’d noticed my first set of solutions didn’t fit the answers, so assumed I’d misunderstood and switched it.

My code was quite short and matched the correct answer. Using the ratio of country price to city price greater than 1.1 prints the item as too expensive.

print('Items that cost over 10% more than city items')
for i in range(19):
     if country_price[i] / city_price[i] > 1.1:

My solution:


print([c[i] for i in range(len(c)) if country_price[i]/city_price[i] > 1.1])

Another way to calculate the percentage:

print('Country Items that exceed 10% in cost\n'
      '-------------------------------------- ')
# Please notice \n inside one string will insert a jump to the next line 
for supplylist , cityprice, countyprice in \
    zip(cleaningsupplies_list, city_price ,country_price ):

    percentage = ((countyprice - cityprice) / countyprice) * 100

    if  percentaje > 10 :
        print(f'{supplylist} is {percentage:.2f}% more expensive')
        # :.2f will format the percentage value to 2 decimals