Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

36 bytes added, 16:39, 8 September 2017
LAB REVIEW
:# What is the purpose of using functions in a Python script?
:# Write Python code to define a function called '''greetings() ''' that when called will greet the user by name and on the next line display the current date:# Why is it useful for functions to accept '''arguments ''' passed-up upon function execution?:# What is the purpose of the '''import ''' command? What can be the consequence if the import command is not used prior to running a function by name?
:# Write Python code to define a function called '''join()''' that excepts two arguments which will be be stored as the variables called '''word1''' and '''word2''' respectively during the execution of the function.
:# What is the command to return a value from a function?
:# What is the purpose of the '''system() ''' function?:# What is the purpose of a '''list'''?
:# Assume that the following command was issued at the ipython3 prompt: '''mylist = [ 'apple', 1, 'grape', 2, 'banana', 3, ]'''<br>Based on the command issued above, what are the results of the following commands?<ol type="a"><li>mylist[0]</li><li>mylist[3]</li><li>mylist[-1]</li><li>mylist[0:1]</li></ol>
:# Assume that the following command was issued at the ipython3 prompt: '''combined_list = [ [7, 5], ['x', 'y'], [ 5, 'f' ] ]'''<br>Based on the command issued above, what are the results of the following commands?<ol type="a"><li>combined_list[0]</li><li>combined_list[1]</li><li>combined_lsit[1][0]</li><li>combined_list[2][0:2]</li></ol>
:# Briefly explain the purpose of each of the following functions (methods) that can be used with lists: '''append''', '''insert''', '''remove''', '''sort''', '''copy'''.</li>
:# Write the '''functions ''' that perform the following operations on a list:<ol type="a"><li>Returns the length of the list</li><li>Returns the smallest value in the list</li><li>Returns the largest value in the list</li></ol>
:# Write a Python script to display all of the elements within a simple list.
13,420
edits