Skip to content

Week 1 - Programming as a way of Thinking

First things First, How do you learn?

Learning Styles

Introduction to Python Programming

Overview

Welcome to CIS-12 and the Python programming language. In this lecture, we will explore the fundamentals of Python and dive into some of the core concepts that will help you get started with this powerful and versatile language.

What is Python?

Python is a high-level, general-purpose programming language that has gained immense popularity in recent years. It is known for its simplicity, readability, and flexibility, making it an excellent choice for beginners and experienced programmers alike. Python is used in a wide range of applications, from web development and data analysis to scientific computing and machine learning.

Setting up Your Development Environment

Before we dive into the Python language, let’s make sure you have the necessary tools installed on your computer.

Installing PyCharm

PyCharm is a powerful Integrated Development Environment (IDE) that makes it easy to write, run, and debug Python code.

To install PyCharm, follow these steps:

  • Visit the official PyCharm website and download the version suitable for your operating system. The PyCharm Community Edition is adequate for this course.
  • Run the installer and follow the on-screen instructions to complete the installation process.
  • Once installed, you can launch PyCharm and start creating your first Python project.

Installing Git

We will also be utilizing and installing Git this semseter. Git is a version control system that allows you to track changes in your code, collaborate with others, and manage your project’s history.

Let’s install Git on your system:

  • Visit the official Git website (https://git-scm.com/downloads) and download the appropriate version for your operating system.
  • Run the installer and follow the on-screen instructions to complete the installation process.
  • Once installed, you can open a terminal or command prompt and verify the installation by running the git --version command.

Now that you have PyCharm and Git set up, you’re ready to start coding in Python!!! …Probably…

Python? Maybe…

Depending on your system you may also need to install Python. PyCharm often comes with a Python interpreter defined, but in the event it doesn’t, you may need to install the official version of Python.

  • Python is available for free on the official Python website, and the installation process is straightforward. Once you have Python installed, you can start writing and running your first Python programs.

Alternatives to PyCharm IDE

While PyCharm is a popular choice, there are several other IDEs available for Python development. Some popular alternatives include:

  • Visual Studio Code: A free, open-source IDE developed by Microsoft, which offers excellent support for Python and a wide range of other programming languages.
  • Spyder: A free, open-source IDE designed specifically for scientific and data-oriented Python development.
  • Eclipse: A popular, open-source IDE that also provides a Python development environment with the help of plugins like PyDev.
  • Google’s Jupyter Colab

Using Google’s Jupyter Colab

Another option for writing and running Python code is Google’s Jupyter Colab. Jupyter Colab is a cloud-based Jupyter Notebook environment that allows you to write and execute Python code directly in your web browser, without the need to install any additional software.

To get started with Jupyter Colab:

  1. Visit the Jupyter Colab website at https://colab.research.google.com/.
  2. You can either create a new notebook or open an existing one.
  3. In the notebook, you can write and execute Python code, as well as add rich text, images, and other multimedia content.
  4. Jupyter Colab also provides access to various Python libraries and tools, making it a great choice for data analysis, machine learning, and scientific computing tasks.

Python Basics

Arithmetic Operators

Let’s start by exploring the basic arithmetic operators in Python. We’ll cover addition, subtraction, multiplication, division, and exponentiation, and see how we can use these operators to perform calculations.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Addition
print(30 + 12)  # Output: 42

# Subtraction
print(43 - 1)  # Output: 42

# Multiplication
print(6 * 7)  # Output: 42

# Division
print(84 / 2)  # Output: 42.0

# Integer Division
print(84 // 2)  # Output: 42

# Exponentiation
print(7 ** 2)  # Output: 49

Expressions and Order of Operations

Next, we’ll learn about expressions, which are combinations of operators and values/operands, and explore the order of operations in Python.

1
2
3
4
5
6
# Expression with multiple operators
print(6 + 6 ** 2)  # Output: 42

# Order of operations (PEMDAS)
print(12 + 5 * 6)  # Output: 42
print((12 + 5) * 6)  # Output: 102
PEMDAS

Strings

In addition to numbers, Python can also work with text, which is represented as strings. We’ll learn how to create, concatenate, and manipulate strings.

If you have a hard time remembering the word String, just remember that a string is characters strung together like beads on a string.

1
2
3
4
5
6
7
8
9
# Creating strings
print('Hello')
print("world")

# Concatenating strings
print('Well, ' + "it's a small " + 'world.')  # Output: "Well, it's a small world."

# Repeating strings
print('Spam, ' * 4)  # Output: "Spam, Spam, Spam, Spam, "

Types and Type Conversion

Python has several built-in data types, including integers, floating-point numbers, and strings. We’ll explore how to work with these types and learn how to convert between them.

1
2
3
4
5
6
7
8
9
# Checking types
print(type(2))  # Output: <class 'int'>
print(type(42.0))  # Output: <class 'float'>
print(type('Hello'))  # Output: <class 'str'>

# Type conversion
print(int(42.9))  # Output: 42
print(float(42))  # Output: 42.0
print(int('126'))  # Output: 126

Debugging and Troubleshooting

As we progress through the lecture, we’ll discuss the importance of debugging and troubleshooting, which are essential skills for any programmer. We’ll cover common types of errors, such as syntax errors, and strategies for identifying and resolving them.

Debugging Tips for PyCharm

Conclusion

You should now have a solid understanding of the fundamentals of Python programming, including arithmetic operations, expressions, strings, and data types. You’ll be well on your way to becoming a proficient Python programmer. Remember, the key to success is practice, so be sure to experiment with the code examples and try writing your own programs.

Happy coding!

Now a quick lesson on Git… If time permits!

Git Forking Workflow