Computer Science  ·  Level 6
Artificial Intelligence Concepts
Chapter 3: Python programming environment
📚 8 Topics
⚑ What you will be able to do

By the end of this chapter, you will be able to:

  • Install Python correctly by following the proper procedures.
  • Use Python syntax accurately to write clear and error-free code.
  • Identify and use different Python data types appropriately in your programs.
  • Apply control structures in Python correctly, following best programming practices.
  • Develop functions in Python that work efficiently and solve problems effectively.
  • Use Object Oriented Programming concepts to create well-structured and reusable Python code.
  • Utilize scientific modules in Python correctly to support data analysis and computations.
  • Create Python applications using scientific modules that perform tasks effectively and reliably.

Mastering these skills will help you become confident in programming with Python, opening doors to exciting opportunities in AI and technology fields!

The Python programming environment forms the foundation for implementing artificial intelligence (AI) solutions in computer science. Mastery of setting up Python enables professionals to leverage its extensive libraries and frameworks essential for AI development. In Kenya’s growing tech landscape, from fintech startups in Nairobi to data science teams in county governments, establishing a robust Python environment is a critical first step for coding, testing, and deploying AI models efficiently.

3.1 Installation of Python

Installing Python correctly ensures that developers have access to the latest features and security updates necessary for AI applications. The installation process involves downloading the appropriate setup files and running them to configure Python on a computer system. This section details how Kenyan computer science professionals can install Python on their machines to prepare for AI programming tasks.

3.1.1 Downloading Python Set Up

Downloading Python involves obtaining the correct installer from the official Python website or trusted sources to guarantee authenticity and security. This process varies slightly depending on the operating system in use, such as Windows, macOS, or Linux, which are common in Kenyan academic and professional environments.

Selecting the Correct Version

Choosing the appropriate Python version is crucial because different AI libraries and frameworks may have specific version requirements. For instance, Python 3.8 or higher is generally recommended for compatibility with TensorFlow and PyTorch used in AI projects at institutions like Strathmore University.

  • Latest Stable Release: Opt for the most recent stable release to access improved features and security patches.
  • Compatibility with Libraries: Verify that the version supports essential AI libraries like NumPy, Scikit-learn, and Keras.
  • System Architecture: Select 32-bit or 64-bit installer matching the computer’s architecture to ensure optimal performance.
  • Operating System Specific Installer: Download the installer tailored to your OS (Windows executable, macOS pkg, or Linux tarball).
  • Official Source: Always download from the official Python website (python.org) to avoid malware or corrupted files.

Internet Connectivity and Download Location

Reliable internet access is necessary to download the installer, especially in Kenyan regions with variable connectivity. Choosing a download location on the computer that is easy to locate, such as the Downloads folder or Desktop, simplifies subsequent installation steps.

  • Stable Connection: Use a stable network to prevent incomplete downloads.
  • Download Folder: Save the installer in an accessible folder to avoid confusion during installation.
  • File Naming: Keep the default file name to avoid errors during execution.
  • Backup Copy: Consider saving a backup copy on a USB drive for offline installations.
  • Version Documentation: Download related documentation files if available for reference during setup.

Verifying the Download

After downloading, verifying the file integrity ensures that the installer is complete and unaltered. This step is particularly important in environments where data corruption during download is common.

  • Checksum Validation: Use MD5 or SHA256 checksums provided on the Python website to verify the installer.
  • File Size Check: Compare the downloaded file size with the expected size listed on the download page.
  • Digital Signature: Check for a digital signature to confirm the source authenticity.
  • Antivirus Scan: Run a security scan to detect potential threats.
  • Test Run: Open the installer to confirm it launches without errors.

Downloading Additional Tools

Some AI development workflows require supplementary tools like Integrated Development Environments (IDEs) or package managers. For example, Visual Studio Code or PyCharm is widely used by developers at the Kenya Medical Research Institute for Python coding.

  • IDEs: Download and install an IDE suitable for Python development.
  • Package Managers: Ensure pip is included or download it separately for managing Python packages.
  • Virtual Environment Tools: Consider tools like virtualenv for managing project dependencies.
  • Documentation Resources: Download offline documentation if internet access is limited.
  • Community Support Tools: Install plugins or extensions that enhance AI development productivity.

3.1.2 Running Python Set Up

Running the Python setup configures the programming environment by installing core components and optionally adding features that facilitate AI programming tasks. Proper execution of this step is essential to enable seamless usage of Python in various Kenyan computer science projects.

Installation Options and Customization

The Python installer provides options to customize the installation to suit specific needs, such as adding Python to the system PATH or selecting optional features.

  • Add Python to PATH: Selecting this option allows running Python from any command prompt without specifying the full path.
  • Customize Installation: Choose this to select optional features like documentation, pip, and test suite.
  • Install for All Users: Useful in shared environments like university computer labs.
  • Advanced Options: Enable features such as precompiling standard library files to improve performance.
  • Default Settings: For most users, the default installation settings suffice.

Step-by-Step Installation Procedure

Following a systematic approach ensures Python is installed correctly without errors that could hamper AI development workflows.

  1. Launch Installer: Double-click the downloaded setup file to start the installation wizard.
  2. Select Installation Type: Choose between ‘Install Now’ for default settings or ‘Customize Installation’ for more control.
  3. Configure Optional Features: If customizing, select features like pip, IDLE, and documentation.
  4. Set Advanced Options: Decide on adding Python to PATH and precompiling standard libraries.
  5. Begin Installation: Click ‘Install’ to copy files and configure Python on the system.
  6. Complete Setup: Wait for the process to finish and verify installation success.

Post-Installation Verification

After installation, confirming that Python is correctly set up avoids future disruptions during AI coding.

  • Command Prompt Test: Open a terminal or command prompt and type python --version to check the installed version.
  • Interactive Shell: Launch the Python interactive shell by typing python and executing simple commands.
  • Pip Availability: Verify pip installation by running pip --version to manage Python packages.
  • IDLE Access: Open IDLE, Python’s integrated development and learning environment, to write and run scripts.
  • Environment Variables: Confirm that Python’s path is correctly added to system environment variables.

Handling Installation Errors

Encountering errors during installation is common, especially in environments with restricted permissions or outdated systems.

  • Permission Issues: Run the installer as an administrator to resolve access problems.
  • Conflicting Versions: Uninstall previous Python versions to prevent conflicts.
  • Antivirus Interference: Temporarily disable antivirus software that might block installation.
  • Corrupted Installer: Re-download the installer if errors persist.
  • System Requirements Check: Ensure the computer meets minimum requirements for Python.

Practice Questions

  1. Explain why selecting the correct Python version is critical for AI programming in Kenyan computer science projects. (6 marks)
  2. Describe the steps involved in downloading the Python installer for a Windows operating system. (8 marks)
  3. List and explain five optional features available during Python installation and their relevance to AI development. (10 marks)
  4. Outline the procedure to verify a successful Python installation on a Linux system. (6 marks)
  5. Identify three common installation errors and suggest practical solutions for each in the context of a university IT lab. (6 marks)
The rest of this chapter
🔒

Create a free account to open more of this chapter.

Free: practical guides, quick cards, workplace scenarios and more.

Create a free account
🔒3.2 Python syntax

In the Kenyan computer science landscape, mastering Python syntax is essential for professionals who build AI applications, data analysis tools, and automation scripts. Python's clear and readable syntax makes it a preferred language for rapid development acro…

🔒3.3 Python data types

In the Kenyan computer science landscape, mastery of Python data types is essential for professionals working on artificial intelligence projects, data analysis, and software development. Data types form the foundation of how data is stored, manipulated, and i…

🔒3.4 Control structures in Python

Selection control structures, also known as decision-making statements, allow a program to choose different execution paths depending on conditions. This capability is crucial in AI systems where decisions must be made based on input data or model predictions.…

🔒3.5 Functions in Python

Functions are fundamental building blocks in Python programming that promote modularity, code reuse, and abstraction. For computer science professionals in Kenya, mastering functions is critical for developing scalable AI applications, such as modular machine…

🔒3.6 Object Oriented Python

Object-oriented programming (OOP) is a core paradigm in Python that allows developers to model real-world entities as objects. In the Kenyan software development industry, especially among firms building scalable enterprise applications for sectors like bankin…

🔒3.7 Scientific Modules in Python

In the Kenyan computer science landscape, proficiency in scientific modules within Python is essential for data analysis, machine learning, and artificial intelligence development. Professionals working in sectors such as fintech, healthcare analytics, and agr…

🔒3.8 Creation of applications using Scientific Modules

In the Kenyan computer science landscape, the development of robust applications for data analysis, machine learning, and artificial intelligence increasingly relies on scientific modules available in Python. These modules provide pre-built functionalities tha…

Chapter Summary

This chapter began with detailed guidance on the installation of Python, covering the steps for downloading and running the Python setup process. It then explored Python syntax, introducing the Zen of Python and the importance of Python Enhancement Proposals 8 (PEP 8) for writing clean code, along with variable declaration and commenting practices. The discussion progressed to Python data types, explaining fundamental types such as integers, floats, booleans, sets, dictionaries, tuples, lists, and strings, highlighting their roles in programming. Control structures including selection and looping were examined to show how Python manages decision-making and repetition in code. The chapter also covered functions, distinguishing between built-in, user-defined, and lambda functions, emphasizing their utility in structuring programs. Object-oriented programming concepts were introduced through the creation of classes, class variables, and class methods, demonstrating how Python supports modular and reusable code. Finally, the chapter presented key scientific modules such as Pandas, Numpy, and Matplotlib, and concluded with the process of creating applications using these scientific libraries to handle data analysis and visualization effectively.

Self-Assessment

🔒 PDFDownload this self-assessment, with answers

A. Written Assessment

  1. What is the first step in installing Python on a Windows machine? (2 marks)
  2. Explain the significance of the Zen of Python in coding style. (3 marks)
🔒20 more in this section.

Chapter Examination Questions

🔒 PDFDownload these examination questions, with worked answers

SECTION A (40 Marks) - Answer ALL Questions

  1. Describe the steps involved in downloading and installing Python on a Windows PC in a Kenyan university computer lab. (4 marks)
  2. Explain the significance of the Zen of Python in guiding Python programming style. (4 marks)
🔒18 more in this section.

Chapter Practical Activities

Practical 1: Install and Verify Python Programming Environment

Computer Science · Level 6
Artificial Intelligence Concepts
PRACTICAL ASSESSMENT
TIME: 4 HOURS
⬇ PDFCandidate Instructions (Candidate Tool)

Type: Individual

INSTRUCTIONS TO CANDIDATE:
1.  You are required to perform the following task:
i.  Download the latest Python 3.x installer for Windows and install Python 3.10.8 on the computer with default settings, then verify installation by running the Python interpreter and displaying the version.
2.  You have been provided with the following resources for the practical task:
Tools & EquipmentMaterials
Working Computer
Internet Access
USB flash drive with Python installer
⬇ PDFResources Required (Cutting List)
S/NItemQuantity
1Working Computer1 Pc per Candidate
2Internet Access1 Access point per Candidate
3USB flash drive with Python installer1 Pc per Candidate
⬇ PDFAssessor Guide
Items to be EvaluatedMarks AvailableMarks ObtainedComments
TASK 1: Python Installation and Verification
Candidate connects computer to internet or accesses USB flash drive
(Award 2 marks if candidate accesses installation source correctly, else 0)
2
Candidate downloads the correct Python 3.x installer from python.org
(Award 4 marks for downloading official and latest Python 3.x installer, else 0)
4
Candidate runs the Python installer and selects default installation options
(Award 5 marks if installation runs without error and uses default options, else 0)
5
Candidate completes installation successfully and closes installer
(Award 3 marks if installation completes with no errors, else 0)
3
Candidate opens command prompt or terminal and runs 'python --version'
(Award 3 marks if command prompt opened and 'python --version' run correctly, else 0)
3
Candidate verifies and displays Python version output matching installed version
(Award 3 marks if Python version output matches installed version, else 0)
3
Candidate runs interactive Python interpreter and exits cleanly
(Award 3 marks if Python interpreter opens and exits without error, else 0)
3
Sub-Total23
PRODUCT CHECKLIST
Python 3.10.8 installed correctly and verified by version display
(Award 7 marks if Python installation is verified and interpreter runs correctly, else 0)
7
Sub-Total7
GRAND TOTAL30
ASSESSMENT OUTCOME:   ☐ Competent    ☐ Not Yet Competent (competent if at least 50%)

Practical 2: Develop a Python script demonstrating correct syntax, PEP 8 style, and Zen of Python principles

Computer Science · Level 6
Artificial Intelligence Concepts
PRACTICAL ASSESSMENT
TIME: 4 HOURS
⬇ PDFCandidate Instructions (Candidate Tool)

Type: Individual

INSTRUCTIONS TO CANDIDATE:
1.  You are required to perform the following task:
i.  Write a Python script of at least 30 lines that demonstrates correct syntax, follows PEP 8 style guidelines, and includes comments explaining five Zen of Python principles.
2.  You have been provided with the following resources for the practical task:
Tools & EquipmentMaterials
Computer with Python IDE installedReference materials on PEP 8 and Zen of Python
Python 3.8+ interpreter
⬇ PDFResources Required (Cutting List)
S/NItemQuantity
1Computer with Python IDE installed1 Pc per Candidate
2Python 3.8+ interpreter1 Pc per Candidate
3Reference materials on PEP 8 and Zen of Python1 Set per Candidate
⬇ PDFAssessor Guide
Items to be EvaluatedMarks AvailableMarks ObtainedComments
TASK 1: Python Script Development
Started Python IDE correctly
(Award 2 marks for correctly launching and setting up the IDE, else 0)
2
Implemented Python code with correct syntax
(Award 10 marks for no syntax errors and correct Python constructs, else 0)
10
Adhered to PEP 8 style guidelines including naming conventions, indentation, and line length
(Award 12 marks for consistent PEP 8 compliance, else 0)
12
Included comments explaining at least five Zen of Python principles
(Award 2 marks for each clearly explained principle, else 0)
10
Script runs successfully and outputs expected results or messages
(Award 6 marks if script executes without runtime errors and outputs as intended, else 0)
6
Sub-Total40
PRODUCT CHECKLIST
Completed Python script with at least 30 lines, correct syntax, PEP 8 style, and comments on Zen of Python
(Award 20 marks if all criteria met as per task instruction, else 0)
20
Sub-Total20
GRAND TOTAL60
ASSESSMENT OUTCOME:   ☐ Competent    ☐ Not Yet Competent (competent if at least 50%)
🔒

Free: practical guides, quick cards, workplace scenarios and more.

Create a free account
🔒Declare and use variables with comments in PythonPractical 3
🔒Python Script for Demonstrating Basic Data TypesPractical 4
🔒Python Program to Create and Manipulate List, Tuple, Set, and DictionaryPractical 5
🔒Python Program to Implement Control Structures for Student GradingPractical 6
🔒Develop Python functions using built-in and user-defined methodsPractical 7
🔒Create and use lambda functions in PythonPractical 8
🔒Define a Python class with class variables and create instancesPractical 9
🔒Implement Python Class with Class Methods to Manage Student RecordsPractical 10
🔒Data Manipulation and Visualization Using Pandas in PythonPractical 11
🔒Perform numerical operations using Numpy arrays in PythonPractical 12
🔒Create Various Plots Using Matplotlib in PythonPractical 13
🔒Develop a Python program combining data types and control structuresPractical 14
Flashcards 20 cards Study deck ▾
Question
1

↻ Tap card to reveal answer
🔒

18 more in this section.

Create a free account
Test Yourself 16 questions Start quiz ▾
0%
0 / 2
🔒

14 more in this section.

Create a free account
Am I competent?

At the start of this chapter we promised you would be able to:

  • Install Python correctly by following the proper procedures.
  • Use Python syntax accurately to write clear and error-free code.
  • Identify and use different Python data types appropriately in your programs.
  • Apply control structures in Python correctly, following best programming practices.
  • Develop functions in Python that work efficiently and solve problems effectively.
  • Use Object Oriented Programming concepts to create well-structured and reusable Python code.
  • Utilize scientific modules in Python correctly to support data analysis and computations.
  • Create Python applications using scientific modules that perform tasks effectively and reliably.

Tick each one you can genuinely do.

So, are you there yet?

You're competent when you can confidently do 50% or more of what this chapter promised.

Sign in to record how you're doing.