Difference between revisions of "CSC111 Homework 3 Solutions"

From dftwiki3
Jump to: navigation, search
(Problem 2)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
--[[User:Thiebaut|D. Thiebaut]] 03:23, 25 February 2010 (UTC)
 
--[[User:Thiebaut|D. Thiebaut]] 03:23, 25 February 2010 (UTC)
 
----
 
----
 
+
<onlydft>
 
==Problem 2==
 
==Problem 2==
  
Line 48: Line 48:
 
.
 
.
 
</source>
 
</source>
 +
 +
==Problem 3==
 +
 +
<source lang="python">
 +
.
 +
 +
# hw3c.py
 +
# 111c-aw
 +
# Andrea Spain
 +
# This program takes a list of words and extracts every 54th word,
 +
# starting at the 54th. It then prints them, forming a quote. The
 +
# name of the author is printed on a second line.
 +
 +
from hw3words import words  #--- words is a list of words ---#
 +
 +
def main():
 +
    #--- Creates empty list. ---#
 +
    quote = [ ]
 +
 +
    #--- Starting at index 54 in words, appends items to the list using a step
 +
    # of 54. It stops at the length of the list. ---#
 +
    for i in range(54, len( words ), 54):
 +
        quote.append( words[ i ] )
 +
 +
    #--- Prints the quote part itself, minus the last word. ---#
 +
    for i in range( 0, len(quote)-3 ):   
 +
        print quote[i],
 +
   
 +
    #--- Prints the last word of the quote. ---#
 +
    print quote[-3]
 +
   
 +
    #--- Prints the last two words (the name) onto a separate line. ---#
 +
    for i in range( -2, 0):
 +
        print quote[i],
 +
   
 +
main()
 +
 +
.
 +
</source>
 +
 +
</onlydft>
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
[[Category:CSC111]][[Category:Python]][[Category:Homework]]

Latest revision as of 08:44, 7 September 2011

--D. Thiebaut 03:23, 25 February 2010 (UTC)



...