Chapter 2: Getting Started
GETTING STARTED WITH PYTHON
Unit 2: Core Fundamentals & Environment Setup
2.1. Downloading and Installation of Python IDE (PyCharm)
To write and run Python scripts efficiently, we need two software tools installed on our computer system:
1. Python Interpreter: The core engine that reads, translates, and executes our Python statements line by
line.
2. IDE (Integrated Development Environment): A specialized text editor designed specifically for coding. It
provides tools such as syntax highlighting, automated error checking, and a built-in terminal to run scripts
easily. In this course, we use PyCharm Community Edition, which is free and industry-standard.
Step-by-Step Setup Guide:
• Step 1: Download and Install Python
Go to the official website [Link]. Download the latest stable executable installer for your operating
system. Run the installer and critically make sure to check the box labeled "Add Python to PATH"
before clicking install. This enables your system to recognize Python from any terminal window.
• Step 2: Download PyCharm
Visit [Link]/pycharm. Scroll down to locate the PyCharm Community Edition (do not download
the Professional Edition as it requires a paid license). Click download.
• Step 3: Install PyCharm
Launch the downloaded installer. Proceed through the setup steps using the default configurations, and
finalize the installation process.
• Step 4: Establish a New Project
Open PyCharm. Select New Project. Choose a directory path where your academic files will reside.
PyCharm will automatically locate your installed Python interpreter. Click Create to launch your
workspace.
2.2. Anatomy of Python Program
A Python program consists of simple instructions organized systematically. Unlike older languages that use
complex structural markers (like curly braces or semicolons), Python relies heavily on readable English
keywords and clean structural layouts.
Page 1
Chapter 2: Getting Started
# Calculate square area Comment (Ignored by Python)
Variable & Assignment
side = 5
Built-in Function
print(side * side)
Figure 1: Anatomy and foundational parts of a minimal, standard Python script.
The standard parts of a script include:
• Keywords: Reserved terms (e.g., if, while, def) that have pre-defined meanings.
• Variables: Named memory containers used to hold data inputs (e.g., side = 5).
• Functions: Named, reusable code commands that execute structured tasks (e.g., print() handles data
display).
• Statements: A complete instruction line intended for execution.
2.3. Write your first Hello World! Script
The traditional entry point into any programming discipline is writing an automated script that prints text onto
the terminal output display screen.
Inside your PyCharm workspace environment, generate a clean text file titled [Link] and input the exact
code line below:
print("Hello, World!")
Execution Procedure:
1. Right-click anywhere within your active editor window area.
2. Locate and click the Run 'main' selection option.
3. Observe the console output pane that launches automatically at the bottom of the user interface window:
Hello, World!
2.4. Guidelines for creating Script
To build scalable, transparent, and error-free programmatic workflows, scripts must adhere to standard
stylistic layouts. Code readability directly impacts long-term software maintainability.
Page 2
Chapter 2: Getting Started
2.4.1. Importance of comments
Comments are text entries inserted into scripts exclusively for human programmers. The underlying Python
interpreter completely passes over these lines without execution.
• Single-Line Comments: Denoted by placing a hash character (#) at the start of the line.
• Multi-Line Comments (Docstrings): Enclosed using clean sets of triple quotation marks.
# This single-line comment describes the variable declaration statement directly
beneath it
student_grade = 92.5
"""
This multi-line comment chunk allows developers to supply
extended context or step-by-step logic summaries
for sophisticated computing algorithms.
"""
Value of Comments: They document programmatic design intent. They prevent confusion when multiple
instructors, developers, or students collaborate on the same file, explaining why an operational pathway was
implemented.
2.4.2. Spacing
Python explicitly avoids arbitrary curly brackets or line-terminating semicolons. Instead, it utilizes structural
whitespace spacing rules to dictate line execution hierarchy.
• Mandatory Code Indentation: Indentation refers to leading whitespace positions placed at the absolute
start of a coding line. Python relies on consistent indentation to define code blocks (such as defining code
that lives inside a conditional statement or a loop structure). A standard indentation level requires exactly
four empty spaces. Mixing regular space-bar strokes with standard tab spacing inputs will trigger file
parsing crashes.
• Vertical Blank Lines: Use isolated vertical blank lines to divide separate block logical sequences or
functional blocks to reduce visual fatigue.
• Horizontal Operator Spacing: Insert explicit blank spaces flanking assignment symbols or operators for
clear readability (write x = 10 instead of x=10).
2.5. Programming Errors
Errors in computational programming are universally classified as bugs. They are segmented into three
logical categories based on precisely when and why they manifest during the program lifecycle.
Page 3
Chapter 2: Getting Started
1. SYNTAX ERRORS 2. RUNTIME ERRORS 3. LOGICAL ERRORS
Broken structural rules. The script Crashes midway. Code rules are Flawed output. Script executes
fails to launch entirely because grammatically valid, but an from start to end without crashing,
Python cannot parse the invalid impossible operation is attempted but outputs mathematically
code statements. during execution. incorrect data answers.
2.5.1. Syntax Error
A Syntax Error occurs when code statements violate Python's formal language rules. PyCharm flags these
immediately using red wavy underline marks.
# Syntax Error Example: An open bracket is missing its closing counterpart
print("Welcome to Python Study Guide"
2.5.2. Runtime Errors
A Runtime Error occurs after a valid program begins executing. The statement syntax is perfectly clean, but
the interpreter encounters a condition that is physically impossible to fulfill, halting execution immediately.
# Runtime Error Example: Division by absolute zero value is impossible
total_score = 500
completed_tests = 0
average_score = total_score / completed_tests
2.5.3. Logical Errors
A Logical Error is the most elusive bug type. The system generates no syntax warnings and finishes
execution without any operational crashes. However, the calculation logic is wrong, causing the code to yield
flawed outputs.
# Logical Error Example: Faulty average calculation sequence due to missing bracket
rules
exam_one = 80
exam_two = 90
# Faulty logic: standard arithmetic rules divide exam_two first, then add exam_one
calculated_average = exam_one + exam_two / 2
print(calculated_average) # Outputs 125 instead of correct mathematical average 85
Page 4
Chapter 2: Getting Started
2.6. Exercise
Section A: Conceptual Identification
Examine the descriptions below and categorize each scenario as a Syntax Error, Runtime Error, or
Logical Error:
1. An accounting script operates seamlessly but consistently prints tax totals as negative values
because a subtraction operator was inverted.
2. A student tries running a script containing prnt("Hello") and the system blocks execution
instantly.
3. A database script attempts to retrieve information from a data storage variable that was completely
erased from memory prior to that command line.
Section B: Practical Application Challenges
1. Construct a script in PyCharm named exercise_2.py. Insert functional comments detailing your
name, course title, and assignment date.
2. Write a program using clean spacing guidelines that prints out the exact text structure below:
* System Initialization Complete *
Loading Workspace Modules...
3. Introduce a deliberate error into your print script by removing a quotation mark. Observe how the
PyCharm IDE flags the error before fixing it to achieve successful execution.
Page 5