Challenge - 5 Problems
Variable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ trace
intermediate2:00remaining
Trace the value of variable after assignments
Consider the following steps where a variable is assigned new values. What is the final value of
x after all steps?Intro to Computing
x = 5 x = x + 3 x = x * 2 x = x - 4
Attempts:
2 left
💡 Hint
Calculate step by step: start with 5, add 3, then multiply by 2, then subtract 4.
✗ Incorrect
Start with x = 5. Then x + 3 = 8. Next multiply by 2: 8 * 2 = 16. Finally subtract 4: 16 - 4 = 12. So the final value is 12.
🧠 Conceptual
intermediate1:30remaining
Identify the correct description of variable storage
Which option best describes what happens when a variable stores a value in a computer?
Attempts:
2 left
💡 Hint
Think about how a variable keeps information for later use.
✗ Incorrect
A variable acts like a labeled box in the computer's memory where a value is kept until needed. It does not send the value to the screen or delete it immediately.
❓ Comparison
advanced2:00remaining
Compare variable types and their storage sizes
Which option correctly orders these variable types from smallest to largest typical storage size?
Attempts:
2 left
💡 Hint
Think about how much space each type usually needs in memory.
✗ Incorrect
Booleans usually need 1 bit or byte, integers need more bytes, floating-point numbers need even more, and strings can vary but often require the most space.
❓ identification
advanced1:30remaining
Identify the error in variable naming
Which variable name is invalid in most programming languages?
Attempts:
2 left
💡 Hint
Variable names usually cannot start with a number.
✗ Incorrect
Variable names cannot start with digits. Option B starts with '2', which is invalid. Other options start with letters or underscore, which are allowed.
🚀 Application
expert2:00remaining
Determine the output after variable swapping
Given the code below, what is the value of
a and b after execution?Intro to Computing
a = 10 b = 20 a, b = b, a
Attempts:
2 left
💡 Hint
Look at how the values are swapped in one line.
✗ Incorrect
The line a, b = b, a swaps the values of a and b. So a becomes 20 and b becomes 10.