0
0
Goprogramming~30 mins

Program stability concepts in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Program Stability Concepts in Go
📖 Scenario: You are building a simple Go program that processes a list of tasks with their durations. You want to make sure the program handles unexpected situations gracefully to stay stable.
🎯 Goal: Build a Go program that creates a map of tasks and durations, sets a maximum allowed duration, filters tasks that exceed this duration, and prints the filtered tasks. This teaches how to keep a program stable by controlling input and output.
📋 What You'll Learn
Create a map called tasks with exact entries: "Email": 30, "Meeting": 90, "Coding": 120, "Break": 15
Create an integer variable called maxDuration and set it to 60
Use a for loop with variables task and duration to iterate over tasks and create a new map filteredTasks with only tasks having duration less than or equal to maxDuration
Print the filteredTasks map
💡 Why This Matters
🌍 Real World
Filtering tasks by duration helps keep programs stable by avoiding processing tasks that take too long.
💼 Career
Understanding how to filter and control data flow is important for writing reliable and maintainable Go programs in software development.
Progress0 / 4 steps
1
Create the initial tasks map
Create a map called tasks with these exact entries: "Email": 30, "Meeting": 90, "Coding": 120, "Break": 15
Go
Hint

Use map[string]int to create a map with string keys and int values.

2
Set the maximum allowed duration
Create an integer variable called maxDuration and set it to 60
Go
Hint

Use := to declare and assign maxDuration in one step.

3
Filter tasks by duration
Use a for loop with variables task and duration to iterate over tasks and create a new map called filteredTasks with only tasks having duration less than or equal to maxDuration
Go
Hint

Use make(map[string]int) to create an empty map. Use for task, duration := range tasks to loop.

4
Print the filtered tasks
Write fmt.Println(filteredTasks) to print the filteredTasks map
Go
Hint

Use fmt.Println to print the map. The output should show only tasks with duration 60 or less.