Challenge - 5 Problems
Python Interactive vs Script Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output difference between interactive and script mode
Consider this Python code snippet run in interactive mode and script mode. What is the output in each mode?
Python
x = 5 x + 3
Attempts:
2 left
💡 Hint
In interactive mode, expressions are automatically printed. In script mode, only explicit print statements show output.
✗ Incorrect
In interactive mode, typing 'x + 3' evaluates and prints 8 automatically. In script mode, without print(), no output appears.
🧠 Conceptual
intermediate2:00remaining
Behavior of variable persistence
Which statement correctly describes variable persistence in Python interactive mode vs script mode?
Attempts:
2 left
💡 Hint
Think about how interactive mode keeps the session alive.
✗ Incorrect
Interactive mode keeps variables alive during the session. Script mode runs fresh each time, so variables reset.
❓ Predict Output
advanced2:00remaining
Output of code with print in script mode
What is the output when running this code as a script?
Python
def greet(): return 'Hello' print(greet())
Attempts:
2 left
💡 Hint
Look at what print() does with the function return value.
✗ Incorrect
The function returns 'Hello', and print() outputs it to the console.
❓ Predict Output
advanced2:00remaining
Output difference with print in interactive mode
What is the output when running this code in interactive mode?
Python
def greet(): return 'Hello' greet()
Attempts:
2 left
💡 Hint
Interactive mode shows the return value of expressions.
✗ Incorrect
In interactive mode, the return value of greet() is shown as a string with quotes.
🧠 Conceptual
expert2:00remaining
Why script mode is preferred for programs
Why is script mode generally preferred over interactive mode for running complete Python programs?
Attempts:
2 left
💡 Hint
Think about code reuse and persistence.
✗ Incorrect
Script mode lets you save code in files and run anytime, making it better for programs. Interactive mode is for quick tests.