Changes

Jump to: navigation, search

OPS435 Python Lab 2

116 bytes added, 13:31, 25 May 2017
PART 1 - User Input
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): <source># Prompt user for colour to be stored into a variable called colour
colour = input("Type in a colour and press enter: ")
# Display value of variable
print(colour)
print('The colour I typed in is: ' + colour)
</source>
:#Run your Python script 3 times When prompted, type the text: '''red''' and press ENTER. Did anything display? Why not?:#Issue the following in the ipython3 shell:<source>print(using a different colour each time you run )</source>What was displayed?:#Issue the following in the scriptipython3 shell:<source>print('The colour I typed in is: ' + colour)</source>Note what was displayed. What do you notice?
:#Exit the ipython3 shell, download the check script and check your work. Enter the following commands from the bash shell.<source>
cd ~/ops435/lab2/
13,420
edits

Navigation menu