Skip to content

Latest commit

 

History

History
53 lines (28 loc) · 1.96 KB

File metadata and controls

53 lines (28 loc) · 1.96 KB

Practice Questions & Solutions — Environment & Setup

📝

Practice set — covers SL No 17–20 (installing Python, running scripts, and the interactive shell). Answer each from memory before opening the solution.

Q1. What does REPL stand for, and what is it useful for?

  • 💡 Solution & explanation

    Answer: Read–Eval–Print–Loop — the interactive Python shell you start by typing python (or python3) with no file.

    Explanation: It reads one statement, evaluates it, prints the result, and loops. It's ideal for quick experiments, testing a snippet, or inspecting objects — but it doesn't save your work, so use a script file for anything real.

Q2. How do you run a saved script called app.py from the terminal?

  • 💡 Solution & explanation

    Answer:

    python app.py

    (or python3 app.py on systems where python still means Python 2).

    Explanation: The interpreter executes the file top to bottom. You must be in the file's directory or give its full/relative path.

Q3. How do you confirm Python is installed and which version you have?

  • 💡 Solution & explanation

    Answer:

    python --version

    Explanation: It prints something like Python 3.12.1. On macOS/Linux, the system may ship an old python; prefer python3 and pip3 to be explicit about Python 3.

Q4. What's the practical difference between working in the REPL and writing a .py file in an editor/IDE?

  • 💡 Solution & explanation

    Answer: The REPL is ephemeral and line-by-line (great for exploration, lost on exit); a .py file is saved, repeatable, and shareable, and is how you build real programs.

    Explanation: Editors/IDEs (VS Code, PyCharm) add syntax highlighting, autocomplete, debugging, and a run button, making larger projects manageable in a way the bare REPL cannot.