Difference between revisions of "CSC111 Lab 1 Solutions 2014"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- __TOC__ =Solution programs= <br /> <source lang="python"> # some solution programs for Lab 1 # CSC111 # D. Thiebaut # (by the way, lines that start with a # sig...")
 
 
(2 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
=Solution programs=
 
=Solution programs=
 
<br />
 
<br />
 +
<onlydft>
 
<source lang="python">
 
<source lang="python">
  
Line 91: Line 92:
  
 
<br />
 
<br />
=Playing with semantics=
+
<br />
* All these various loops print the same thing...
+
 
 
<br />
 
<br />
 
<br />
 
<br />
<source lang="python">
 
  
list = [ "Lea Jones", "Julie Fleur", "Anu Vias", "Anna Bell", "Lynn Grave" ]
+
<br />
  
 +
<center><videoflash>TgZxW6w6w8c</videoflash></center>
  
#--- first loop example ---
+
<br />
for name in list:
+
</onlydft>
    print( "+-" + "-" * len( name ) + "-+" )
+
<br />
    print( "|", name, "|" )
 
    print( "+-" + "-" * len( name ) + "-+" )
 
    print()
 
 
 
#--- separator ---
 
print( "\n" + "-"*80 + "\n" )
 
 
 
 
 
#--- second loop example ---
 
for name in list:
 
    noDashes = len( name ) + 2
 
    line    = '-' * noDashes
 
    print( '+' + line + '+')
 
    print( '|' , name , '|' )
 
    print( '+' + line + '+')
 
   
 
 
 
#--- separator ---
 
print( "\n" + "-"*80 + "\n" )
 
 
 
 
 
#--- third loop example ---
 
for name in list:
 
    noChars  = len( name )
 
    noDashes = noChars + 2
 
    line    = '+' + '-'*noDashes + '+'
 
    print( line )
 
    print( '|' , name , '|' )
 
    print( line )
 
   
 
 
 
</source>
 
 
 
 
<br />
 
<br />
  
 
<br />
 
<br />
 
 
[[Category:CSC111]][[Category:Python]][[Category:Labs]]
 
[[Category:CSC111]][[Category:Python]][[Category:Labs]]

Latest revision as of 16:36, 10 May 2014

--D. Thiebaut (talk) 11:23, 30 January 2014 (EST)


Solution programs



...