Difference between revisions of "CSC111 Homework 6 2015"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <showafterdate after="20150305 16:00" before="20150601 00:00"> =Preparation= <br /> * Create a program called '''testHw6.py''' with the code available on [[CSC111...")
 
Line 6: Line 6:
 
<br />
 
<br />
 
* Create a program called '''testHw6.py''' with the code available on [[CSC111 testHw6.py 2015|this page]].  Save it in the same place where you will store your '''hw6.py''' program.
 
* Create a program called '''testHw6.py''' with the code available on [[CSC111 testHw6.py 2015|this page]].  Save it in the same place where you will store your '''hw6.py''' program.
 +
* Create a second program, called '''hw6.py'''.  This program will contain all the functions that you are asked to write for this assignment.  Add the code below to your '''hw6.py''' code:
 +
<br />
 +
<source lang="python">
 +
# hw6.py
 +
# yourname here
 +
# This program contains functions that solve all the problems
 +
# of Homework 6, including a function0() that is given as a
 +
# bonus.
  
 +
 +
# function0: receives a string, removes leading and trailing whitespace from
 +
# it, and capitalize all its words, and add two stars at both ends.  Return the
 +
# new string.
 +
def function0( name ):
 +
    name = "**" + name.strip().title() + "**"
 +
    return name
 +
 +
 +
# ================================================
 +
#                                        M A I N
 +
# ================================================
 +
def main():
 +
 +
    # --------------------------------------------------------
 +
    # testing function0() with 3 different strings
 +
    for name in [ "ARTHUR", "  smith COLLEGE  ", " lei  " ]:
 +
        newName = function0( name )
 +
        print( name )
 +
        print( newName )
 +
    print()
 +
 +
 +
 +
if __name__=="__main__":
 +
  main()
 +
 +
</source>
 +
<br />
  
  

Revision as of 17:25, 1 March 2015

--D. Thiebaut (talk) 16:18, 1 March 2015 (EST)


<showafterdate after="20150305 16:00" before="20150601 00:00">

Preparation


  • Create a program called testHw6.py with the code available on this page. Save it in the same place where you will store your hw6.py program.
  • Create a second program, called hw6.py. This program will contain all the functions that you are asked to write for this assignment. Add the code below to your hw6.py code:


# hw6.py
# yourname here
# This program contains functions that solve all the problems
# of Homework 6, including a function0() that is given as a 
# bonus.


# function0: receives a string, removes leading and trailing whitespace from
# it, and capitalize all its words, and add two stars at both ends.  Return the
# new string.
def function0( name ):
    name = "**" + name.strip().title() + "**"
    return name


# ================================================
#                                        M A I N
# ================================================
def main():

    # --------------------------------------------------------
    # testing function0() with 3 different strings
    for name in [ "ARTHUR", "  smith COLLEGE  ", " lei   " ]:
        newName = function0( name )
        print( name )
        print( newName )
    print()



if __name__=="__main__":
   main()



</showafterdate>