Difference between revisions of "CSC111 HW 1 Solutions 2014"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- 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 ...")
 
(hw1x.py)
Line 86: Line 86:
 
<br />
 
<br />
 
<source lang="python">
 
<source lang="python">
#Youyou Tian
+
# hw1x.py
#CSC111
+
# Youyou Tian
#1/31/14
+
# CSC111
#Prints the names of the 7 dwarfs all inside a box on one row
+
# 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"]
 
dwarfNames = ["Sleepy", "Sneezy", "Bashful", "Happy", "Grumpy", "Dopey", "Doc"]

Revision as of 09:38, 10 February 2014

--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 + " "

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