CS101: Introduction to Programming I

About This Course

CS101: Introduction to Programming I – Your Gateway to the World of Coding

Course Overview

Welcome to CS101: Introduction to Programming I, your first step towards becoming a software developer! This course is designed for absolute beginners with no prior programming experience. We’ll guide you through the fundamental concepts of computer programming using Python, a versatile and widely used language known for its readability and ease of learning. Throughout this course, you’ll learn how to write, test, and debug simple programs, understand data structures, and apply problem-solving techniques using computational thinking. We will cover topics from basic syntax to control flow, functions, and object-oriented programming principles. Get ready to unlock the power of coding and build your own software! [1]

What You Will Learn

This course provides a comprehensive introduction to the world of programming, with a focus on practical skills and real-world applications. You will learn to think like a computer scientist, breaking down complex problems into manageable steps and implementing solutions in Python. The curriculum is structured to take you from the very basics of programming to more advanced topics, ensuring a solid foundation for your future studies or career in technology.

Key Learning Objectives:

  • Fundamental Programming Concepts: Grasp the core principles of programming, including variables, data types, operators, and control structures (if/else statements, loops). [2]
  • Python Basics: Learn the syntax and semantics of the Python programming language, from writing your first “Hello, World!” program to understanding its powerful features.
  • Data Structures: Explore fundamental data structures like lists, dictionaries, and tuples, and understand how to use them effectively to store and manipulate data.
  • Functions: Write reusable code blocks by defining and calling functions, making your programs more modular and efficient.
  • Object-Oriented Programming (OOP): Get an introduction to OOP concepts like classes, objects, inheritance, and polymorphism, which are essential for building complex applications.
  • Problem Solving: Develop computational thinking skills to analyze problems and design algorithmic solutions.
  • Debugging: Learn how to identify and fix errors in your code, a crucial skill for any programmer.
  • Version Control with Git: Understand the basics of version control using Git for managing code changes and collaborating with others.
  • Testing: Write basic tests to ensure the reliability of your code.
  • File Handling: Learn to read from and write to files, enabling your programs to interact with the file system.

Why Take This Course?

CS101 provides a solid foundation for anyone interested in pursuing a career in software development or related fields. It equips you with the essential skills and knowledge to understand and create software applications. Python is a highly sought-after language in various industries, including web development, data science, machine learning, and automation. This course will not only teach you how to code but also foster your problem-solving abilities, which are valuable in any profession. [3]

Career Benefits

Completing CS101 can open doors to various career opportunities, including:

  • Junior Software Developer: Assist in the development of software applications under the guidance of senior developers.
  • Web Developer (Front-End or Back-End): Build and maintain websites using Python frameworks like Django or Flask.
  • Data Analyst: Analyze data using Python libraries like Pandas and NumPy to extract insights and trends.
  • Automation Engineer: Automate repetitive tasks using Python scripting.
  • Quality Assurance (QA) Tester: Write automated tests to ensure the quality of software applications.
  • Game Developer (Entry-Level): Create simple games using Python libraries like Pygame.

Even if you don’t pursue a career directly related to programming, the skills you learn in CS101 will enhance your analytical thinking and problem-solving abilities, making you a more valuable asset in any field. The knowledge you gain from this course will provide a strong foundation for learning more advanced programming concepts and technologies in the future. [4]

In-Depth: Data Structures

Data structures are a fundamental concept in computer science, providing a way to organize and store data for efficient access and modification. In this section, we will delve deeper into the most common data structures in Python: lists, tuples, dictionaries, and sets. Understanding these structures is crucial for writing effective and performant code.

Lists

Lists are one of the most versatile data structures in Python. They are ordered, mutable (changeable), and can contain items of different data types. Lists are defined by enclosing a comma-separated sequence of items in square brackets [].

Example:

# Creating a list
my_list = [1, "hello", 3.14, True]

# Accessing elements
print(my_list[1])  # Output: hello

# Modifying elements
my_list[0] = "new item"
print(my_list)  # Output: ["new item", "hello", 3.14, True]

# Appending elements
my_list.append("another item")
print(my_list) # Output: ["new item", "hello", 3.14, True, "another item"]

Tuples

Tuples are similar to lists, but they are immutable, meaning their contents cannot be changed after creation. Tuples are defined by enclosing a comma-separated sequence of items in parentheses ().

Example:

# Creating a tuple
my_tuple = (1, "hello", 3.14, True)

# Accessing elements
print(my_tuple[1])  # Output: hello

# Tuples are immutable, so the following line would raise an error:
# my_tuple[0] = "new item"  # TypeError: 'tuple' object does not support item assignment

Dictionaries

Dictionaries are unordered collections of key-value pairs. They are mutable and are defined by enclosing a comma-separated sequence of key-value pairs in curly braces {}. Each key must be unique and immutable (e.g., a string, number, or tuple).

Example:

# Creating a dictionary
my_dict = {"name": "John", "age": 30, "city": "New York"}

# Accessing values
print(my_dict["name"])  # Output: John

# Modifying values
my_dict["age"] = 31
print(my_dict)  # Output: {"name": "John", "age": 31, "city": "New York"}

# Adding new key-value pairs
my_dict["occupation"] = "Software Engineer"
print(my_dict) # Output: {"name": "John", "age": 31, "city": "New York", "occupation": "Software Engineer"}

Sets

Sets are unordered collections of unique items. They are mutable and are defined by enclosing a comma-separated sequence of items in curly braces {}. Sets are useful for performing mathematical set operations like union, intersection, and difference.

Example:

# Creating a set
my_set = {1, 2, 3, 4, 4} # Duplicate elements are automatically removed
print(my_set)  # Output: {1, 2, 3, 4}

# Adding elements
my_set.add(5)
print(my_set)  # Output: {1, 2, 3, 4, 5}

# Set operations
set1 = {1, 2, 3}
set2 = {3, 4, 5}

print(set1.union(set2))  # Output: {1, 2, 3, 4, 5}
print(set1.intersection(set2))  # Output: {3}

In-Depth: Control Flow

Control flow tools are essential for directing the execution of your program based on certain conditions. In this section, we will explore if, for, and while statements in more detail, providing you with the knowledge to create dynamic and responsive programs.

if Statements

if statements are used to execute a block of code only if a certain condition is true. You can also use elif (else if) and else to handle multiple conditions.

Example:

x = 10

if x > 0:
    print("x is positive")
elif x < 0:
    print("x is negative")
else:
    print("x is zero")

for Loops

for loops are used to iterate over a sequence (such as a list, tuple, or string) and execute a block of code for each item in the sequence.

Example:

# Iterating over a list
my_list = ["apple", "banana", "cherry"]
for fruit in my_list:
    print(fruit)

# Using the range() function
for i in range(5):
    print(i)  # Output: 0, 1, 2, 3, 4

while Loops

while loops are used to execute a block of code as long as a certain condition is true.

Example:

count = 0
while count < 5:
    print(count)
    count += 1

In-Depth: Object-Oriented Programming (OOP)

Object-Oriented Programming (OOP) is a programming paradigm based on the concept of “objects”, which can contain data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods). A key feature of OOP is that it allows for the creation of reusable and modular code. In this section, we will introduce the core concepts of OOP in Python: classes, objects, inheritance, and polymorphism.

Classes and Objects

A class is a blueprint for creating objects. An object is an instance of a class. You can think of a class as a cookie cutter, and the cookies you create with it are the objects.

Example:

# Defining a class
class Dog:
    # Class attribute
    species = "Canis familiaris"

    # Initializer / Instance attributes
    def __init__(self, name, age):
        self.name = name
        self.age = age

    # Instance method
    def description(self):
        return f"{self.name} is {self.age} years old"

    # Another instance method
    def speak(self, sound):
        return f"{self.name} says {sound}"

# Creating instances of the Dog class
dog1 = Dog("Buddy", 5)
dog2 = Dog("Lucy", 3)

# Accessing attributes and calling methods
print(dog1.description())  # Output: Buddy is 5 years old
print(dog2.speak("Woof!"))  # Output: Lucy says Woof!

Inheritance

Inheritance is a mechanism in which one class acquires the property of another class. For example, a child inherits the traits of his/her parents. With inheritance, we can reuse the fields and methods of the existing class.

Example:

# Parent class
class Animal:
    def __init__(self, name):
        self.name = name

    def speak(self):
        raise NotImplementedError("Subclass must implement abstract method")

# Child class inheriting from Animal
class Dog(Animal):
    def speak(self):
        return "Woof!"

# Another child class inheriting from Animal
class Cat(Animal):
    def speak(self):
        return "Meow!"

# Creating instances of the child classes
dog = Dog("Buddy")
cat = Cat("Whiskers")

print(dog.name)  # Output: Buddy
print(dog.speak())  # Output: Woof!
print(cat.name)  # Output: Whiskers
print(cat.speak())  # Output: Meow!

Polymorphism

Polymorphism is the ability of an object to take on many forms. In Python, polymorphism allows us to use a single interface with different underlying forms such as data types or classes.

Example:

# Using the speak method with different objects
animals = [Dog("Buddy"), Cat("Whiskers")]

for animal in animals:
    print(animal.speak())

# Output:
# Woof!
# Meow!

In-Depth: File Handling

File handling is an important part of any web application. Python has several functions for creating, reading, updating, and deleting files.

Reading Files

The open() function is used to open a file. It takes two parameters: filename and mode. The mode can be 'r' for reading, 'w' for writing, 'a' for appending, and 'x' for creating.

Example:

# Opening a file in read mode
f = open("demofile.txt", "r")
print(f.read())

Writing to an Existing File

To write to an existing file, you must add a parameter to the open() function: 'a' for append or 'w' for write.

Example:

# Appending to a file
f = open("demofile.txt", "a")
f.write("Now the file has more content!")
f.close()

# Opening and reading the file after appending
f = open("demofile.txt", "r")
print(f.read())

# Overwriting the content
f = open("demofile.txt", "w")
f.write("Woops! I have deleted the content!")
f.close()

# Opening and reading the file after writing
f = open("demofile.txt", "r")
print(f.read())

In-Depth: Modules and Packages

As you write larger and more complex programs, it becomes essential to organize your code into manageable and reusable units. In Python, this is achieved through modules and packages. This section will introduce you to these concepts and show you how to use them to structure your code effectively.

Modules

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. For example, if you have a file named my_module.py, you can import it into another Python script and use the functions and variables defined within it.

Example:

Let’s say you have a file named my_module.py with the following content:

# my_module.py

def greet(name):
    return f"Hello, {name}!"

PI = 3.14159

You can import this module and use its contents in another script:

# main.py
import my_module

print(my_module.greet("Alice"))  # Output: Hello, Alice!
print(my_module.PI)  # Output: 3.14159

Packages

Packages are a way of structuring Python’s module namespace by using “dotted module names”. For example, the module name A.B designates a submodule named B in a package named A. Packages are directories that contain a special file named __init__.py. This file can be empty, but it indicates that the directory should be treated as a package.

Example:

Consider the following directory structure:

my_package/
    __init__.py
    module1.py
    module2.py

module1.py:

def function1():
    return "This is function 1"

module2.py:

def function2():
    return "This is function 2"

You can import and use the modules within the package as follows:

# main.py
from my_package import module1, module2

print(module1.function1())  # Output: This is function 1
print(module2.function2())  # Output: This is function 2

In-Depth: Error and Exception Handling

Even the most carefully written code can sometimes produce errors. Understanding how to handle these errors is a crucial part of programming. In Python, errors are managed through a mechanism called exceptions. This section will introduce you to the different types of errors and show you how to use exception handling to make your programs more robust.

Syntax Errors

Syntax errors, also known as parsing errors, are perhaps the most common kind of complaint you get while you are still learning Python. A syntax error occurs when the parser detects an incorrect statement.

Example:

# This line will cause a syntax error because of the missing colon
if x > 0
    print("x is positive")

Exceptions

Even if a statement or expression is syntactically correct, it may cause an error when an attempt is made to execute it. Errors detected during execution are called exceptions and are not unconditionally fatal: you will soon learn how to handle them in Python programs.

Example:

# This will cause a ZeroDivisionError
10 / 0

# This will cause a NameError
print(undefined_variable)

Handling Exceptions

The try and except block in Python is used to catch and handle exceptions. The try block contains the code that may cause an exception, and the except block contains the code that handles the exception.

Example:

try:
    x = 1 / 0
except ZeroDivisionError:
    print("You cannot divide by zero!")

try:
    with open("non_existent_file.txt") as f:
        read_data = f.read()
except FileNotFoundError:
    print("File not found!")

References

[1] Python Software Foundation. (2026). The Python Tutorial. Python 3.14.2 documentation. https://docs.python.org/3/tutorial/index.html
[2] Bell, A., Grimson, E., & Guttag, J. (2016). 6.0001 Introduction to Computer Science and Programming in Python. MIT OpenCourseWare. https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/
[3] Google for Developers. (2024). Google’s Python Class. https://developers.google.com/edu/python
[4] Stanford University. (n.d.). Computer Science 101. Stanford Online. https://online.stanford.edu/courses/soe-ycscs101-computer-science-101

Learning Objectives

a:5:{i:0;s:45:"Learn the fundamentals of Python programming.";i:1;s:60:"Develop problem-solving skills using computational thinking.";i:2;s:55:"Gain a foundation for a career in software development.";i:3;s:74:"Understand core programming concepts like variables, loops, and functions.";i:4;s:39:"Build simple programs and applications.";}

Material Includes

  • Online video lectures
  • Coding exercises and assignments
  • Downloadable code examples
  • Interactive quizzes
  • Online forum for Q&A

Requirements

  • a:3:{i:0;s:41:"No prior programming experience required.";i:1;s:24:"Basic computer literacy.";i:2;s:46:"Access to a computer with internet connection.";}

Target Audience

  • a:5:{i:0;s:41:"Beginners with no programming experience.";i:1;s:40:"Students interested in computer science.";i:2;s:38:"Individuals looking to change careers.";i:3;s:40:"Professionals seeking to automate tasks.";i:4;s:38:"Anyone curious about learning to code.";}
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare

Don't have an account yet? Sign up for free