0
0
Pythonprogramming~20 mins

Why variables are needed in Python - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Variable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this code using variables?

Look at this Python code that uses variables to store numbers and add them. What will it print?

Python
a = 5
b = 3
c = a + b
print(c)
AError
B53
C8
DNone
Attempts:
2 left
💡 Hint

Variables hold values. Adding two numbers stored in variables gives their sum.

🧠 Conceptual
intermediate
1:30remaining
Why do we use variables in programming?

Choose the best reason why variables are important in programming.

ATo make the program run faster
BTo avoid writing any numbers
CTo decorate the code with colors
DTo store and reuse data easily
Attempts:
2 left
💡 Hint

Think about how you keep information to use later in a recipe or a list.

Predict Output
advanced
2:00remaining
What is the output when variables are updated?

Look at this code where a variable changes value. What will it print?

Python
x = 10
x = x + 5
print(x)
A15
BError
C5
D10
Attempts:
2 left
💡 Hint

Variables can change their stored value by using their old value in calculations.

🧠 Conceptual
advanced
1:30remaining
What happens if you don’t use variables?

Why would a program be hard to write or understand if it never used variables?

AYou would have to repeat the same data many times
BThe program would run faster
CYou could never do math operations
DThe program would automatically fix errors
Attempts:
2 left
💡 Hint

Think about writing a shopping list without using names for items.

Predict Output
expert
2:30remaining
What is the final value of the variable after this code?

Trace this code carefully. What is the value of total at the end?

Python
total = 0
for i in range(1, 5):
    total = total + i
print(total)
AError
B10
C0
D15
Attempts:
2 left
💡 Hint

Sum numbers from 1 to 4 by adding each to total.