Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Python Interactive Mode vs Script Mode
📖 Scenario: Imagine you want to quickly test some math calculations and then save a small program to run later. Python offers two ways to do this: interactive mode and script mode.Interactive mode lets you type commands one by one and see results immediately, like a calculator. Script mode lets you write a full program in a file and run it all at once.
🎯 Goal: You will create a simple Python program that adds two numbers and prints the result. You will first try the commands one by one in interactive mode, then write the same commands in a script file and run it.
📋 What You'll Learn
Create two variables with exact names and values
Create a variable to hold the sum of the two numbers
Use a print statement to display the sum
Understand the difference between typing commands interactively and running a script
💡 Why This Matters
🌍 Real World
Python interactive mode is great for quick experiments and learning. Script mode is used to write programs that can be saved and run anytime.
💼 Career
Understanding both modes helps you test ideas fast and build reusable programs, a key skill for any Python developer.
Progress0 / 4 steps
1
Create two number variables
Create two variables called num1 and num2 with values 10 and 5 respectively.
Python
Hint
Use the equals sign = to assign values to variables.
2
Add the two numbers
Create a variable called total that adds num1 and num2 together.
Python
Hint
Use the plus sign + to add numbers.
3
Print the sum
Use a print statement to display the value of total.
Python
Hint
Use print(variable_name) to show the value on screen.
4
Run and observe output
Run the program and observe the output. The output should be the sum of num1 and num2. Type print(total) in interactive mode or run the script file to see the result.
Python
Hint
The output should be 15 because 10 + 5 = 15.
Practice
(1/5)
1. What is the main difference between Python interactive mode and script mode?
easy
A. Interactive mode is slower than script mode.
B. Interactive mode runs files; script mode runs commands one by one.
C. Interactive mode runs commands one by one; script mode runs a whole file at once.
D. Script mode shows results immediately after each command.
Solution
Step 1: Understand interactive mode behavior
Interactive mode lets you type and run one command at a time and see the result immediately.
Step 2: Understand script mode behavior
Script mode runs a saved file with many lines of code all at once, not line-by-line interactively.
Final Answer:
Interactive mode runs commands one by one; script mode runs a whole file at once. -> Option C
Quick Check:
Interactive = one command, Script = whole file [OK]
Hint: Interactive = one command; script = whole file run [OK]
Common Mistakes:
Confusing which mode runs commands one by one
Thinking script mode shows immediate results after each line
Believing interactive mode runs whole files
2. Which of the following is the correct way to start Python in interactive mode from a terminal?
easy
A. python script.py
B. python
C. python -i script.py
D. python run script.py
Solution
Step 1: Identify command to start interactive mode
Typing python alone in the terminal starts Python in interactive mode.
Step 2: Understand other options
python script.py runs a script, python -i script.py runs script then interactive, and python run script.py is invalid syntax.
Final Answer:
python -> Option B
Quick Check:
Just type python to start interactive mode [OK]
Hint: Type 'python' alone to start interactive mode [OK]
Common Mistakes:
Using 'python script.py' to start interactive mode
Confusing flags like -i without understanding
Typing invalid commands like 'python run script.py'
3. What will be the output if you run this code in interactive mode line by line?
print('Hello')
2 + 3
print('Done')
medium
A. Hello\nDone
B. Hello\n3\nDone
C. Hello\nNone\nDone
D. Hello\n5\nDone
Solution
Step 1: Analyze print statements in interactive mode