# Python Fundamentals Practice Problem #7

My Code:

``````Paste your code here
``````

What I expected to happen:

What actually happened:

``````Paste output/error here
``````

Hi all,

I’m on practice problem 7 for the python fundamentals course Pt 1 and the answer is below.

file = open(“laptops.csv”)

# create the dictionary mapping the prices to the laptop names

price_to_name = {}
for row in rows:
price = int(row)
name = row
if price in price_to_name:
price_to_name[price].append(name)
else:
price_to_name[price] = [name]

laptop1 = None
laptop2 = None

# look for a solution

for row in rows:
price = int(row)
# this laptop’s cost is price, so if there is a laptop that
# costs 5000 - price then their total price is exactly 5000
if price == 2500 and len(price_to_name) >= 2:
laptop1 = price_to_name
laptop2 = price_to_name
elif 5000 - price in price_to_name:
laptop1 = price_to_name[price]
laptop2 = price_to_name[5000 - price]
print(price)

# print the solution

print(laptop1)
print(laptop2)

I am pretty confused on what is happening from the point where it says #look for a solution, and onwards. Is there anyone that can walk me through what is happening beyond that point?

Thanks!

hey @sbolourc

For a start check out this post. Let us know if this still doesn’t helps you much.