CS 212, AI Programming 1
[TOC]
Most programming languages have many things in common:
Once you’ve learned how to work with these concepts in one language, it’s mostly just a matter of learning the new syntax for the next language you learn.
Open a Power Shell Terminal on your computer and check to see if Python is installed on your system using this command:
python --version
If it is installed, the version number will be reported.
Check to see if the Python launcher is installed:
py --version
If it is installed, the version number will be reported.
Download the latest Python installer and run it.
# A simple program to print a greeting
print("Hello, World! Python is running.")
Save the file as hello.py
Run the Program in Command Prompt (CMD) or PowerShell
Open the Command Prompt:
Press the Windows Key + R, type cmd, and press Enter. (Or use the Windows search bar to find “Command Prompt” or “PowerShell”).
Use the cd (Change Directory) command to move to the folder where you saved your script. If you saved it to C:\PythonProjects, you would type: cd C:\PythonProjects
Execute the Script:
Use the python command followed by the file name:
python hello.py
(If python doesn’t work, try using py hello.py instead.)
Output: The Terminal will display the result:
Hello, World! Python is running on Windows.
While macOS comes with a system version of Python pre-installed, it’s outdated and should not be used for development. We will install an up to date version using Homebrew, a package manager for macOS.
In the Terminal, run:
python3 --version
If it’s older than 3.14 (the latest version in October 2026) then update it.
Installation instructions are here.
Open the Terminal:
Press Cmd + Space and type “Terminal,” then press Enter.
Run the Homebrew installation command: Copy and paste the following line into your Terminal and press Enter
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
The script will prompt you to enter your administrator password (it won’t display as you type) and press Enter.
Follow any final on-screen instructions, such as adding Homebrew to your system’s PATH.
In the Terminal, run:
brew install python
Homebrew will download and install the latest stable version of Python.
Verify the Installation
After the installation completes, confirm that the correct version is now recognized by your system.
Check the Python version:
In the Terminal, run:
python3 --version
You should see output confirming the version you just installed (e.g., Python 3.12.2).
Create your Python file: Use a text editor to create a file named hello.py and add the following content:
# A simple program to print a greeting
print("Hello, World! Python is running.")
Open Terminal and Navigate: Open your Terminal and navigate to the directory where you saved hello.py (using the cd command).
Run the script: Execute the file using the Python 3 interpreter:
python3 hello.py
Output: The Terminal will display the output:
Hello, World! Python is running.
Ctrl+Shift+X)..py files in VS Code.Ctrl+Shift+P and type Python: Select Interpreter.main.py).F5 to start debugging, or click the green “Run and Debug” button in the Run view (Ctrl+Shift+D).F10), step into (F11), continue (F5), or stop (Shift+F5).Tips
"args": ["arg1", "arg2"] to your .vscode/launch.json if your script needs command-line arguments.Ctrl+) to run scripts normally with python your_script.py`.; to terminate lines. The end of the line is the end of the line.Here is an implementation of the classic “FizzBuzz” program1 in Python:
# FizzBuzz program
for i in range(1, 10):
output = ""
# Check for divisibility by 3
if i % 3 == 0:
output += "Fizz"
# Check for divisibility by 5
if i % 5 == 0:
output += "Buzz"
# If output is still empty, print the number
if output == "":
print(i)
else:
print(output)
Here is an example of Object Oriented Programming in Python. This car simulator illustrates these of OOP concepts:
Car class has-a an Engine instance.Driver and Passenger are-a special types of Occupant.Engine class.Translate a simple game from either JavaScript or C# into Python.
The game is “die battle”: two players each roll a single six-sided die, and the player with the higher number wins. It requires defining three simple classes:
Die: Represents the physical object that can be rolled.Player: Represents a participant who interacts with the die.DiceBattle: Orchestrates the game flow and holds the game state (the players and the die).Note: Parts of this document were drafted with assistance from Gemini 2.5 Flash 9/30/25
AI Programming Course Materials by Brian Bird, written in 2025, revised in are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
The FizzBuzz program iterates from 1 up to some specified limit. It prints “Fizz” for multiples of 3, “Buzz” for multiples of 5, “FizzBuzz” for multiples of both, or just the number. ↩