Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

691 bytes added, 09:10, 31 May 2017
PART 1 - Using Functions
:Now it's time to create a Python script that uses two functions. One function does not return a value and is simply used (when called) to greet the user, where the other function returns the result of adding two values (stored in variables within the function).
:Now it'''Perform the Following Instructions:''':#Create s time to create a new script '''~/ops435/lab3/lab3ato prompt the user to enter data and display that data on their terminal. Refer to variable name and prompt text information when creating your Python script.py''' Refer to Sample Runs displayed below for exact prompt and store the following content inside:<source>#!/usr/bin/env python3output requirements.
# Function returning string valuedef return_text_value(): name = 'Terry' return 'Good Morning Perform the following Instructions:''' + name
:# Function returning integer valuedef return_number_value(): num1 = 5 num2 = 10 num3 = num1 + num2 return num3Create a new script '''~/ops435/lab3/lab3a.py'''
:::'''Input / Output Requirements'''
 
:::*The script should have a '''Shebang line'''
:::*Below the '''Shebang line''', add an empty line followed by a comment stating: "#return_text_value() function"
:::*Add an empty line followed by the '''return_text_value()''' function definition that you previously entered in the shell.
:::*Add another empty line followed by a comment stating: "#return_number_value() function"
:::*Add another empty line following by the '''return_number_value()''' function definition that you previously entered in the shell.
:::*Add a couple of empty lines, following by a comment stating: "#Main Program"
:::*Add another couple of empty lines, followed by the statements displayed below:<source>
# This IF Statement may seem cryptic and unclear. Any code written under this IF statement will be run when you run your script.
#if __name__ == '__main__':
text = return_text_value()
print(text)
13,420
edits