-3

I have:

inventory = ["shoes, 12, 29.99", "shirts, 20, 9.99", "sweatpants, 25, 15.00", "scarves, 13, 7.75"]
for item in inventory:
    print('The store has {1} {0}, each for {2} USD'.format(item))

and I am trying to get: The store has 12 shoes, each for 29.99 USD . . .

2

2 Answers 2

0

Try using split:

inventory = ["shoes, 12, 29.99", "shirts, 20, 9.99", "sweatpants, 25, 15.00", "scarves, 13, 7.75"]
for item in inventory:
    print('The store has {1} {0}, each for {2} USD'.format(*item.split(', ')))

Output:

The store has 12 shoes, each for 29.99 USD
The store has 20 shirts, each for 9.99 USD
The store has 25 sweatpants, each for 15.00 USD
The store has 13 scarves, each for 7.75 USD
Sign up to request clarification or add additional context in comments.

Comments

0

you need to split the item in for loop, so that you can use those value in .format method.

inventory = ["shoes, 12, 29.99", "shirts, 20, 9.99", "sweatpants, 25, 15.00", "scarves, 13, 7.75"]
for item in inventory:
    print('The store has {1} {0}, each for {2} USD'.format(*item.split(',')))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.