0
0
DSA Pythonprogramming~15 mins

Array Access and Update at Index in DSA Python - Build from Scratch

Choose your learning style9 modes available
Array Access and Update at Index
📖 Scenario: You are managing a list of daily temperatures recorded in a week. Sometimes, you need to check the temperature of a specific day or update it if there was a mistake in recording.
🎯 Goal: Build a simple program that creates a list of temperatures, sets a specific day index to a new temperature, and then prints the updated list.
📋 What You'll Learn
Create a list called temperatures with exactly these values: 23, 25, 22, 20, 24, 26, 21
Create a variable called day_index and set it to 3
Update the temperature at index day_index in temperatures to 19
Print the temperatures list after the update
💡 Why This Matters
🌍 Real World
Lists are used to store collections of data like daily temperatures, sales numbers, or scores. Being able to access and update specific items helps keep data accurate.
💼 Career
Many programming jobs require working with lists or arrays to manage data. Knowing how to access and change elements by index is a fundamental skill.
Progress0 / 4 steps
1
Create the temperatures list
Create a list called temperatures with these exact values in order: 23, 25, 22, 20, 24, 26, 21
DSA Python
Hint

Use square brackets [] to create a list and separate values with commas.

2
Set the day index
Create a variable called day_index and set it to the integer 3
DSA Python
Hint

Use the assignment operator = to set day_index to 3.

3
Update the temperature at the given index
Update the value in the temperatures list at index day_index to 19
DSA Python
Hint

Use square brackets with the index variable to access and update the list element.

4
Print the updated temperatures list
Print the temperatures list to show the updated values
DSA Python
Hint

Use the print() function to display the list.