# 2021 REU Course

This course introduces the REU students to various topics in Intelligent Systems Engineering. The course was taught in Summer 2021.

## Programming with Python

Python is a great languge for doing data science and AI, a comprehensive list of features is available in book form. Please note that when installing Python, you always want to use a venv as this is best practice.

 Introduction to Python (ePub) (PDF)

## Installation of Python

Update to the Video:

Best practices in Python recommend to use a Python venv. This is pretty easy to do and creates a separate Python environment for you so you do not interfere with your system Python installation. Some IDEs may do this automatically, but it is still best practice to install one and bind the IDE against it. To do this:

1. Download Python version 3.9.5 just as shown in the first lecture.

• on Mac:

python3.9 -m venv ~/ENV3
source ~/ENV/bin/activate


you need to do the source every time you start a new window or on mac ass it to .zprofile

• on Windows you first install gitbash and do all yuour terminal work from gitbash as this is more Linux-like. In gitbash, run

python -m venv ~/ENV3
~/ENV/Script/activate


In case you like to add it to gitbash, you can add the source line to .bashrc and/or .bash_profile

1. In case you use VSCode, you can also do it individually in a directory where you have your code.

• On Mac: cd TO YOUR DIR; python3.9 -m venv .
• On Windows cd TO YOUR DIR; python -m venv .

Then start VSCode in the directory and it will ask you to use this venv. However, the global ENV3 venv may be better and you cen set your interpreter to it.

2. On Pycharm we recommend you use the ENV3 and set the clobal interpreter

## Introduction to Python

The first exercise will require a simple for loop, while the second is more complicated, requiring nested for loops and a break statement.

General Instructions: Create two different files with extension .ipnyb, one for each problem. The first file will be named factorial.ipnyb which is for the factorial problem, and the second prime_number.ipnyb for the prime number problem.

1. Write a program that can find the factorial of any given number. For example, find the factorial of the number 5 (often written as 5!) which is 12345 and equals 120. Your program should take as input an integer from the user.

Note: The factorial is not defined for negative numbers and the factorial of Zero is 1; that is 0! = 1.

You should

1. If the number is less than Zero return with an error message.
2. Check to see if the number is Zero—if it is then the answer is 1—print this out.
3. Otherwise use a loop to generate the result and print it out.
2. A Prime Number is a positive whole number, greater than 1, that has no other divisors except the number 1 and the number itself. That is, it can only be divided by itself and the number 1, for example the numbers 2, 3, 5 and 7 are prime numbers as they cannot be divided by any other whole number. However, the numbers 4 and 6 are not because they can both be divided by the number 2 in addition the number 6 can also be divided by the number 3.

You should write a program to calculate prime number starting from 1 up to the value input by the user.

You should

1. If the user inputs a number below 2, print an error message.
2. For any number greater than 2 loop for each integer from 2 to that number and determine if it can be divided by another number (you will probably need two for loops for this; one nested inside the other).
3. For each number that cannot be divided by any other number (that is its a prime number) print it out.