DEV Community

kavin suresh
kavin suresh

Posted on

Python Dictionary

Annachi Kadai

In Tamil Nadu there was shop called Annachi Kadai. The owner of the shop is Pandiyan. Now we learn Python using this case study.

Morning:

In the early morning the goods for shop will come. Then Pandiyan will take a note on the goods.

One day the goods came to his shop and he take a note on it. They are:-

inventory = {
    "apples": 20,
    "bananas": 30,
    "carrots": 15,
    "milk": 10
}
Enter fullscreen mode Exit fullscreen mode

He want to check the list.

print(inventory)
 {
    'apples': 20,
    'bananas': 30,
    'carrots': 15,
    'milk': 10
}
Enter fullscreen mode Exit fullscreen mode

Noon:

As the time going the delivery also increases. So he add more inventories.

inventory["bread"] = 25
inventory["eggs"] = 50
Enter fullscreen mode Exit fullscreen mode

Then he want to check the list

print("Updated Inventory:", inventory)

Updated Inventory: {'apples': 20, 'bananas': 30, 'carrots': 15, 'milk': 10, 'bread': 25, 'eggs': 50}
Enter fullscreen mode Exit fullscreen mode

Afternoon:

Then in the afternoon the quantities of the goods is going less. So he buyed some goods and he want that to add it on the list.

inventory["apples"] += 10 
inventory["milk"] += 5
Enter fullscreen mode Exit fullscreen mode

Then he want to check the list

print("Inventory after Restocking:", inventory)

Inventory after Restocking: {'apples': 30, 'bananas': 30, 'carrots': 15, 'milk': 15, 'bread': 25, 'eggs': 50}
Enter fullscreen mode Exit fullscreen mode

Evening:

In evening many of goods have sold. So he want to remove it from the list.

del inventory["carrots"]
Enter fullscreen mode Exit fullscreen mode

then he want to check the list.

print("Inventory after Removal:", inventory)

Inventory after Removal: {'apples': 30, 'bananas': 30, 'milk': 15, 'bread': 25, 'eggs': 50}
Enter fullscreen mode Exit fullscreen mode

Night:

Before closing the shop. He wants to check the inventory is the inventories are correct.

is_bananas_in_stock = "bananas" in inventory
is_oranges_in_stock = "oranges" in inventory
print(f"Are bananas in stock? {is_bananas_in_stock}")
print(f"Are oranges in stock? {is_oranges_in_stock}")

 Are bananas in stock? True
 Are oranges in stock? False
Enter fullscreen mode Exit fullscreen mode

This things only we learnt in the python class.
Thank You

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo πŸ“Šβœ¨

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay