IT 116: Introduction to Scripting Class 8 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  ex8`
• Check that the directory was created
`ls`
• Go to this new directory
`    cd ex8`

Practice with interactive mode

• Enter Python interactive mode
`python3`
• Practice with logical operators
```>>> 4 < 8 and 8 < 80
>>> 4 > 8 or 8 < 80
>>> not True
>>> not False```
• Write a `while` loop
```>>> numb = 0
>>> while numb < 10:
...     numb = numb + 1
...
>>> numb```
• Write an `if` statement that checks the range of a variable
```>>> age = 25
>>> if 16 <= age <= 65:
... 	print("Your age is in the right range")
... else:
...  	print("Your age is in the wrong range")
...```
• Write some boolean expressions
```>>> 16 <= age  and  age <= 65
>>> 16 <= age <= 65```
• Set some boolean variables
```>>> minor = age < 10
>>> minor
>>> senior = age > 65
>>> senior```
• Write an infinite loop
```>>> while True:
...     print("Are we there yet?")```
You many have to hit Control C many times to stop this loop.
• Quit interactive mode

Control D

Practice with scripts

• Create the script ex8.py
`nano  ex8.py`
• Enter the following text into the script file
• Run this script
`python3  ex8.py`
• You should see
```\$ python3 ex8.py

4 < 8 and 8 < 80: True
4 > 8 or 8 < 80: True
not True: False
not False True

Entering while loop
number: 0
number: 1
number: 2
number: 3
number: 4
number: 5
number: 6
number: 7
number: 8
number: 9
Left while loop
number: 10

Are we there yet? no
Are we there yet? no
Are we there yet? yes
Yeah!