Changes

Jump to: navigation, search

OPS435 Python Lab 2

80 bytes added, 12:23, 1 August 2017
PART 1 - User Input
ipython3
</source>
:#To begin, let's start out with a very basic script. This script will use variables that will display specific information to your terminal. Move to your '''~/ops435/lab2''' directory, create the file '''lab2a.py''' with a text editor containing the following content:<sourcelang="python">
#!/usr/bin/env python3
run lab2a.py
</source>This Python script is not very useful: it displays the same output regardless of the number of times that the Python script is run.<br>The '''input()''' function is used to obtain information from the user and store it into a variable. It is recommended to place a question (or hint) as a argument in the input() function: this will aid the user in typing in the correct information.<br><br>
:#Return to your '''ipython3''' shell and type the following code (do '''NOT''' edit the lab2a.py file, just issue from the shell): <sourcelang="python">
colour = input("Type in a colour and press enter: ")
</source>
:#When prompted, type the text: '''red''' and press ENTER. Did anything display? Why not?
:#Issue the following in the ipython3 shell:<sourcelang="python">print(colour)
</source>What was displayed?
:#Issue the following in the ipython3 shell:<sourcelang="python">print('The colour I typed in is: ' + colour)
</source>Note what was displayed.
:#Exit the ipython3 shell, download the checking script and check your work. Enter the following commands from the bash shell.<sourcelang="bash">
cd ~/ops435/lab2/
pwd #confirm that you are in the right directory
Hi Jen, you are 25 years old.
</source>
:::3. Download the checking script and check your work. Enter the following commands from the bash shell.<sourcelang="bash">
cd ~/ops435/lab2/
pwd #confirm that you are in the right directory

Navigation menu