## IT 116: Introduction to Scripting Class 5 Exercise

• Run an SSH client
Run putty.exe if you have a PC or Terminal if you have a Mac.

### Create a directory for this exercise

• Go to your home directory
`cd`
• Go to your it116 directory
`cd  it116`
• Go to your ex directory
`cd ex`
• Make sure you are in your ex directory
`pwd`
If you are not in /home/UNIX_ID/it116/ex, see me.
• Create a directory for this exercise
`mkdir  ex5`
• Check that the directory was created
`ls`
• Go to this new directory
`cd ex5`

### Practice with interactive mode

• Enter Python interactive mode
`python3`
• Create three variables
```>>> a = 4
>>> b = 5
>>> c = 6```
• Print the values of the variables you just created
`>>> (4, 5, 6)`
Notice that you can print more than one variable at a time.
• Perform some calculations using addition and subtraction
```>>> a + b + c
>>> a + b - c
>>> b - c - a```
• Perform some calculations using the division and remainder operators
```>>> c / a
>>> c // a
>>> c % a```
Notice the difference between the two different types of division.
• Perform some operations using the exponent operator
```>>> a ** 2
>>> a ** 3
>>> a ** 4```
• Perform some calculations involving operator precedence
```>>> a + b * c
>>> (a + b) * c
>>> a + b / c
>>> a + b // c
>>> a + b % c
>>> (a + b) / c
>>> (a + b) // c
>>> (a + b) % c ```
• Quit interactive mode

Control D

### Practice with scripts

• Create the script ex5.py
`nano  ex5.py`
• Enter the following text into the script file
• Run this script
`python3  ex5.py`
• You should see
```a: 4 b: 5 c: 6

a + b + c = 15
a + b - c = 3
b - c - a = -5

c / a  = 1.5
c // a = 1
c % a  = 2

a ** 2 = 16
a ** 3 = 64
a ** 4 = 256

a + b * c    = 34
(a + b) * c  = 54
a + b / c    = 4.833333333333333
a + b // c   = 4
a + b % c    = 9
(a + b) / c  = 1.5
(a + b) // c = 1
(a + b) % c  = 3```