0
0
Goprogramming~30 mins

Practical use cases in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Practical use cases
📖 Scenario: You are working on a small store inventory system. You want to keep track of products and their prices, then find which products are affordable under a certain budget.
🎯 Goal: Build a Go program that stores product prices, sets a budget limit, filters products affordable within that budget, and prints the affordable products.
📋 What You'll Learn
Create a map called products with product names as keys and prices as float64 values
Create a variable called budget with a float64 value
Use a for loop to find products with prices less than or equal to budget
Store affordable products in a new map called affordable
Print the affordable map
💡 Why This Matters
🌍 Real World
Managing product prices and budgets is common in retail and inventory systems.
💼 Career
Understanding maps, loops, and conditionals in Go is essential for backend and systems programming jobs.
Progress0 / 4 steps
1
Create the products map
Create a map called products with these exact entries: "Apple": 1.20, "Banana": 0.80, "Cherry": 2.50, "Date": 3.00, "Eggplant": 1.50
Go
Hint

Use a map literal with string keys and float64 values.

2
Set the budget variable
Create a variable called budget with the float64 value 2.00 inside the main function, below the products map.
Go
Hint

Use a simple variable declaration with := and a float64 value.

3
Filter affordable products
Create a new map called affordable of type map[string]float64. Use a for loop with variables product and price to iterate over products. Inside the loop, add products with price less than or equal to budget to the affordable map.
Go
Hint

Use make to create the map, then a for loop with range to iterate.

4
Print the affordable products
Use fmt.Println to print the affordable map. Remember to import the fmt package at the top.
Go
Hint

Use fmt.Println(affordable) to print the map.