Hai fatto grandi progressi! Ora metterai insieme ciò che hai imparato:
Lavorerai nell’ambiente realistico di un negozio di alimentari che sta organizzando il suo inventario.
Hai due stringhe:
items = "Bubblegum, Chocolate, Pasta"
categories = "Candy Aisle, Pasta Aisle"
Bubblegum, Chocolate, Pasta Candy Aisle, Pasta Aisle
Usa lo slicing per estrarre:
"Bubblegum" → candy1"Chocolate" → candy2"Pasta" → dry_goodsUsa lo slicing per estrarre dalla stringa delle categorie:
"Candy Aisle" → category1"Pasta Aisle" → category2Crea variabili prezzo:
bubblegum_price = "$1.50"
chocolate_price = "$2.00"
pasta_price = "$5.40"
Stampa dichiarazioni formattate nella forma:
We have <candy1> for <bubblegum_price> in the <category1>
We have <candy2> for <chocolate_price> in the <category1>
We have <dry_goods> for <pasta_price> in the <category2>
(Gli indici di slicing sono calcolati sulla base delle stringhe fornite.)
items = "Bubblegum, Chocolate, Pasta"
categories = "Candy Aisle, Pasta Aisle"
# Slicing items
candy1 = items[0:9] # "Bubblegum"
candy2 = items[11:20] # "Chocolate"
dry_goods = items[22:27] # "Pasta"
# Slicing categories
category1 = categories[0:11] # "Candy Aisle"
category2 = categories[13:23] # "Pasta Aisle"
# Prices
bubblegum_price = "$1.50"
chocolate_price = "$2.00"
pasta_price = "$5.40"
# Output
print("We have", candy1, "for", bubblegum_price, "in the", category1)
print("We have", candy2, "for", chocolate_price, "in the", category1)
print("We have", dry_goods, "for", pasta_price, "in the", category2)