CSC111 Lab4 Solutions
# 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():
zoo = [ "pig", "horse", "elephant" ]
count = 0
for animal in zoo:
count = count + 1
for i in range( count ):
print animal,
print
def main6():
for year in [ 2010, 2011, 2012, 2013]:
for sem in [ "spring", "fall" ]:
print sem, year
def main7():
filename = raw_input( "Filename? " )
filenameNoExtension = filename[0:-3]
print filenameNoExtension + "txt"
main1()
main2()
main3()
main4()
main5()
main6()
main7()