🏁 Sfida Finale — Ordinamento dell’Inventario

Hai fatto grandi progressi! Ora metterai insieme ciò che hai imparato:

  • Variabili
  • Tipi di dati
  • Slicing di stringhe
  • Concatenazione
  • Output formattato

Lavorerai nell’ambiente realistico di un negozio di alimentari che sta organizzando il suo inventario.


🛒 Compito

Hai due stringhe:

items = "Bubblegum, Chocolate, Pasta"
categories = "Candy Aisle, Pasta Aisle"

Bubblegum, Chocolate, Pasta Candy Aisle, Pasta Aisle

✔️ Obiettivi

  1. Usa lo slicing per estrarre:

    • "Bubblegum"candy1
    • "Chocolate"candy2
    • "Pasta"dry_goods
  2. Usa lo slicing per estrarre dalla stringa delle categorie:

    • "Candy Aisle"category1
    • "Pasta Aisle"category2
  3. Crea variabili prezzo:

    bubblegum_price = "$1.50"
    chocolate_price = "$2.00"
    pasta_price = "$5.40"
  4. 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>

🧪 Soluzione d’esempio

(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)