Difference between revisions of "CSC111 Lab4 Solutions"

From dftwiki3
Jump to: navigation, search
(Created page with '--~~~~ ---- <source lang="python"> import os def main1(): Id = raw_input( "Please enter Id of student (e.g. aa) " ) command = "111c-" + Id os.system( "lastlog -u…')
 
Line 1: Line 1:
--[[User:Thiebaut|D. Thiebaut]] 20:59, 17 February 2010 (UTC)
+
 
 
----
 
----
 
<source lang="python">
 
<source lang="python">
 +
# Selected solutions for Lab 4
 
import os
 
import os
 
   
 
   
Line 32: Line 33:
  
  
 +
main1()
 +
main2()
 +
main3()
 +
main4()
 
main5()
 
main5()
  
 
</source>
 
</source>

Revision as of 16:01, 17 February 2010


# Selected solutions for Lab 4
import os
 
def main1():
     Id = raw_input( "Please enter Id of student (e.g. aa) " )
     command = "111c-" + Id
     os.system( "lastlog -u " + command )       
 
def main2():
    for Id in "abcdefghijklmnopqrstuvwxyz":
        user = "111c-a" + Id
        os.system( "lastlog -u " + user )

def main3():
     for semester in [ 'a', 'b' ]:
         for Id in "abcdefghijklmnopqrstuvwxyz":
              user = "111c-" + semester + Id
              os.system( "lastlog -u " + user )

def main4():
     for second in "abcdefghijklmnopqrstuvwxyz":
          for first in "abc":
               print first+second,  # comma to stay on the same line
          print # once we've printed 3, go to next line

def main5():
     filename = raw_input( "Filename? " )
     filenameNoExtension = filename[0:-3]
     print filenameNoExtension + "txt"


main1()
main2()
main3()
main4()
main5()