you loop over the items in your products_dict (in your create_products function), if you use Baseball, this key/name becomes an undefined variable, that is a problem.
Okay, I am very confused. I tried to run a replicate of your code:
def create_products(**products_dict):
print(products_dict)
for name, price in products_dict.items():
print(name, price)
create_product(name, price)
# Checkpoint 3
# Update the call to `create_products()` to pass in this dictionary as a series of keyword
create_products(
Baseball = 3,
Shirt = 14,
Guitar = 70,
)
which unpacks the keyword arguments in a dictionary just fine.
Could you copy and paste your code to the forum? So I can actually run the code. Preferable both scripts/files.
# Checkpoint 1
print("My name is {name} and I'm feeling {feeling}.".format(
name = 'Vella', feeling = 'great'
))
# Checkpoint 2
from products import create_product
# Update create_products() to take arbitrary keyword arguments
def create_products(**products_dict):
for name, price in products_dict.items():
create_product(name, price)
# Checkpoint 3
# Update the call to `create_products()` to pass in this dictionary as a series of keyword
create_products(
'Baseball '= 3,
'Shirt' = 14,
"Guitar" = 70,
)
The error msg is: SyntaxError: keyword can’t be an expression
Sorry, I’m not sure how to copy & paste the code. If it’s still not clear, could you please tell me the effective way to copy & paste the code? Thanks!
Never mind. I pressed the view solution button and see what I did wrong. I’m glad that the view solution option doesn’t nuke your code anymore–it just shows the difference between your codes and theirs.
So, the working code is here.
I was confused the same as you guys, but I restarted my exercise and did it again.
# Checkpoint 1
print("My name is {name} and I'm feeling {feeling}.".format(name="Ruslan", feeling="good"
# add your arguments to .format()
))
# Checkpoint 2
from products import create_product
# Update create_products() to take arbitrary keyword arguments
def create_products(**products_dict):
for name, price in products_dict.items():
create_product(name, price)
# Checkpoint 3
# Update the call to `create_products()` to pass in this dictionary as a series of keyword
create_products( Baseball=3,
Shirt=14,
Guitar=70,
)