0
0
Pythonprogramming~20 mins

Python Interactive Mode vs Script Mode - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Python Interactive vs Script Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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
AInteractive mode: 8\nScript mode: 8
BInteractive mode: (no output)\nScript mode: 8
CInteractive mode: 5\nScript mode: 8
DInteractive mode: 8\nScript mode: (no output)
Attempts:
2 left
💡 Hint
In interactive mode, expressions are automatically printed. In script mode, only explicit print statements show output.
🧠 Conceptual
intermediate
2:00remaining
Behavior of variable persistence
Which statement correctly describes variable persistence in Python interactive mode vs script mode?
AVariables persist in both interactive and script mode after execution ends.
BVariables reset after each command in interactive mode but persist in script mode.
CVariables persist across commands in interactive mode but reset each time a script runs.
DVariables never persist in either mode.
Attempts:
2 left
💡 Hint
Think about how interactive mode keeps the session alive.
Predict Output
advanced
2: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())
ANone
BHello
Cgreet
D(no output)
Attempts:
2 left
💡 Hint
Look at what print() does with the function return value.
Predict Output
advanced
2: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()
A'Hello'
BHello
C(no output)
DNone
Attempts:
2 left
💡 Hint
Interactive mode shows the return value of expressions.
🧠 Conceptual
expert
2:00remaining
Why script mode is preferred for programs
Why is script mode generally preferred over interactive mode for running complete Python programs?
ABecause script mode allows saving and reusing code easily, while interactive mode is temporary.
BBecause interactive mode runs code faster than script mode.
CBecause script mode automatically prints all expressions without print().
DBecause interactive mode cannot define functions.
Attempts:
2 left
💡 Hint
Think about code reuse and persistence.