1,234
edits
Changes
→PART 1 - User Input
== PART 1 - User Input ==
:In this section, you will learn how to prompt (ask) the user running the program for input or data. Although you will not be immediately be using the information that the user provided, you will use that information later in this lab to change how a Python script works under in different situations.
'''Storing User Input In Variables'''
:'''Perform the following steps:'''
:#Launch your Centos VM, open your code editor, and a a shell terminal (as a regular user) and start a new ipython3 session:<source>ipython3</source>for executing your code.:#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 Create the file '''lab2a.py''' in your '''~/ops435/lab2''' directory, create the file '''lab2a.py''' with a text editor containing the following content:<source lang="python">
#!/usr/bin/env python3
</source>
:#Try running this script inside ipython3 and study the output:<source>
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 shellAdd another line to your script:<source lang="python">print(colour)
</source>What was displayed?
:#Issue the following in the ipython3 shellAnd replace that line wiht this:<source lang="python">print('The colour I typed in is: ' + colour)
</source>Note what was displayed.
:#Exit the ipython3 shell, Now download the checking script and check your work. Enter Run the following commands from the bash shell.:<source lang="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 Run the following commands from the bash shell.<source lang="bash">
cd ~/ops435/lab2/
pwd #confirm that you are in the right directory