Dictionaries Mission Practice Problems Q12

Screen Link:
https://app.dataquest.io/m/1011/python-fundamentals-practice-problems/12/laptop-purchase

My Code:

laptop1 = None
laptop2 = None
for price1 in price_to_name:
    for price2 in price_to_name:
        if (price1 != price2) and (price1 + price2 == 5000):
            laptop1 = price1
            laptop2 = price2
...

What I expected to happen:
To assign two different prices that could be added to exactly $5000

What actually happened: 
The values of laptop1 and laptop2 remained "None".

Replace this line with the output/error


<!--Enter other details below: -->
Why does this code not work?
1 Like

The code works. It just means that there are no two price values which add up to 5000 and are not the same.

There is no condition in the instructions stating that the prices can’t be the same. They can be the same for different laptops.

1 Like