Changes

Jump to: navigation, search

OPS435 Python Lab 2

83 bytes added, 11:40, 25 May 2017
PART 1 - USER INPUT
:#Try running this script inside ipython3 and study the output:<source>
run lab2a.py
</source><br>This Python script is not very useful: shows it displays the same output every time regardless of the number of times that it the Python script is executedrun.<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, edit the lab2a.py file and add the following code: <source>
# Prompt user for colour to be stored into a variable called colour
colour = input("Type in a colour and press enter: ")
Type in a colour and press enter: red</source>:#Now print out the Display value of variable '''colour''' and it should contain the value you entered after the prompt.<source>
print(colour)
print('The colour I typed in is: ' + colour)
</source>
:#Run your Python script 3 times using a different colour for each time you run the script. What do you notice?
:#If you didn't get the colour you typed in returned, try the above steps with the input() function again.
:#Download the check script and check your work. Enter the following commands from the bash shell.<source>
13,420
edits

Navigation menu