Look at this Python code that uses variables to store numbers and add them. What will it print?
a = 5 b = 3 c = a + b print(c)
Variables hold values. Adding two numbers stored in variables gives their sum.
The variables a and b store numbers 5 and 3. Adding them gives 8, which is printed.
Choose the best reason why variables are important in programming.
Think about how you keep information to use later in a recipe or a list.
Variables let us save data with names so we can use or change it later without rewriting it.
Look at this code where a variable changes value. What will it print?
x = 10 x = x + 5 print(x)
Variables can change their stored value by using their old value in calculations.
Variable x starts at 10, then 5 is added, so x becomes 15 and prints.
Why would a program be hard to write or understand if it never used variables?
Think about writing a shopping list without using names for items.
Without variables, you must write the same values again and again, making code long and confusing.
Trace this code carefully. What is the value of total at the end?
total = 0 for i in range(1, 5): total = total + i print(total)
Sum numbers from 1 to 4 by adding each to total.
The loop adds 1 + 2 + 3 + 4 = 10 to total, which is printed.