CSC111 HW 1 Solutions 2014

From dftwiki3
Jump to: navigation, search

--D. Thiebaut (talk) 09:38, 10 February 2014 (EST)


You'll find here solution programs for Homework #1. There were many good programs and it was hard to choose the best. These programs were chosen because they are nicely organized and documented (you didn't have to document programs for Homework 1).

hw1a.py


# hw1a.py
# Sarah McNeil
# January 31, 2014
# this program prints a list of names
# and encloses each of the names in a box

dwarfNames = ["Sleepy", "Sneezy", "Bashful", "Happy", "Grumpy", "Dopey", "Doc" ]
bar = "+" + "-" * 18 + "+"
for name in dwarfNames:
    print ( bar )
    print ( "|", name, (len (bar)- len (name)-5)*" ", "|" )
    print ( bar )
    print ( )


hw1b.py


# hw1b.py
# Sarah McNeil
# January 31, 2014
# CSC 111
# This program prints a list of names
# and puts the list in one box

dwarfNames = ["Sleepy", "Sneezy", "Bashful", "Happy", "Grumpy", "Dopey", "Doc" ]
bar = "+" + "-" * 18 + "+"
print ( bar )
for name in dwarfNames:
    print ( "|" + name, (len (bar)- len (name)-4)*" ", "|" )

print ( bar )


hw1c.py


# hw1c.py
# Sarah McNeil
# January 31, 2014
# CSC 111
# this program prints a list of names
# in a box and aligns the list
# to the right of the box

dwarfNames = ["Sleepy", "Sneezy", "Bashful", "Happy", "Grumpy", "Dopey", "Doc" ]
bar = "+" + "-" * 18 + "+"
print ( bar )
for name in dwarfNames:
    print ( "|", (len (bar)- len (name)-4)*" ", name + "|" )

print ( bar )


hw1d.py


# hw1c.py
# Sarah McNeil
# January 31, 2014
# CSC 111
# This program prints a list of names
# twice on two sides of a divided box

dwarfNames = ["Sleepy", "Sneezy", "Bashful", "Happy", "Grumpy", "Dopey", "Doc" ]
bar = "+" + "-" * 37 + "+"
print ( bar )

for name in dwarfNames:
    print ("|", " "*(15- len(name)), name, "|", name, " "*(15- len(name)), "|")
    
print ( bar )


hw1x.py


# hw1x.py
# Youyou Tian
# CSC111
# 1/31/14
# Prints the names of the 7 dwarfs all inside a box on one row

dwarfNames = [ "Sleepy", "Sneezy", "Bashful", "Happy", "Grumpy", "Dopey", "Doc" ]
longName = ""

for name in dwarfNames:
    longName = longName + name + " "

longLine = "+" + "-"*len( longName ) + "+"
print ( longLine )
print ( "|"+longName + "|" )
print ( longLine )