CSC111 Homework 1 2014

From dftwiki3
Revision as of 11:42, 30 January 2014 by Thiebaut (talk | contribs) (Optional and Extra Credit)
Jump to: navigation, search

--D. Thiebaut (talk) 10:42, 30 January 2014 (EST)





This homework assignment is due on Thursday 02/06 evening, at midnight. Assignments submitted after this date and time will not be graded.

For this first assignment you should work individually. As soon as we have discussed the article on Pair Programming you can try this method with a partner who's also taking this class.

You should do this homework with Python 3 IDLE, either on your own laptop or on one of the computers in the Science Center. Make sure to save your program to your H: drive if you work on a computer that is not yours.

When you are done with each program you can submit it as explained at the end of this page.




Problem #1

  • Write a python program called hw1a.py (use this exact name, please!) that uses a list of names, defined as follows:
  dwarfNames = [ "Sleepy", "Sneezy", "Bashful", "Happy", "Grumpy", "Dopey", "Doc" ]
and prints them with boxes around them. This time the boxes are all 20 characters in length. The length of the box is fixed.
 +------------------+
 | Sleepy           |
 +------------------+
 
 +------------------+
 | Sneezy           |
 +------------------+

etc...
  • Note that there is one blank line printed between each box.
  • This is just an extension of what we did in Lab #1. Review the lab is you do not know how to get started.


Problem #2

  • Create a program called hw1b.py that uses the same list as in Problem #1:


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


However, your new program should output the names in this fashion:
 +------------------+
 |Sleepy            |
 |Sneezy            |
 |Bashful           |
 |Happy             |
 |Grumpy            |
 |Dopey             |
 |Doc               |
 +------------------+ 
Note that there are now only two lines of dashes, and all the names fit inside the box.


Problem #3

  • Create a program called hw1c.py that uses the same list as in Problem #1.


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


This time, your new program should output the names in this fashion:
 +------------------+
 |            Sleepy|
 |            Sneezy|
 |           Bashful|
 |             Happy|
 |            Grumpy|
 |             Dopey|
 |               Doc| 
 +------------------+
Note that there are now only two lines of dashes, and all the names fit inside the box.

Problem #4

  • Create a program called hw1d.py that uses the same list as in Problem #1.


  dwarfNames = [ "Sleepy", "Sneezy", "Bashful", "Happy", "Grumpy", "Dopey", "Doc" ]
Your assignment for this program is to output the names in this fashion:

 +-------------------------------------+  |           Sleepy | Sleepy           |  |           Sneezy | Sneezy           |  |          Bashful | Bashful          |  |            Happy | Happy            |  |           Grumpy | Grumpy           |  |            Dopey | Dopey            |  |              Doc | Doc              |   +-------------------------------------+

  • Your program must use a loop.


Hint: Try first to make your program generate this output:

Sleepy Sleepy  
Sneezy Sneezy           
Bashful Bashful          
Happy Happy            
Grumpy Grumpy           
Dopey Dopey            
Doc Doc             

Then, when you have this working, modify your program to get this:

Sleepy | Sleepy  
Sneezy | Sneezy           
Bashful | Bashful          
Happy | Happy            
Grumpy | Grumpy           
Dopey | Dopey            
Doc | Doc             

Then add the | symbols at both ends of each line. Then add the extra spaces. Then the top and bottom lines of dashes...


Optional and Extra Credit

  • This problem is only for people who have done some programming before and feel they need some more challenge than provided by the other problems. TAs are not allowed to help with this extra-credit problem. If this problem seems too challenging, don't attempt to work on it; I am making it available only to people with previous programming experience.
  • Write a program called hw1x.py that uses the list of names defined as follows:
dwarfNames = [ "Sleepy", "Sneezy", "Bashful", "Happy", "Grumpy", "Dopey", "Doc" ]
  • and that outputs the names all on one line, in a box, as follows:
 +---------------------------------------------+
 |Sleepy Sneezy Bashful Happy Grumpy Dopey Doc | 
 +---------------------------------------------+



Hint: Play with these statements in the console window:
  word1 = "hello"
  word2 = "world!"
  sentence = word1 + " " + word2
  print( sentence )

This should give you some ideas...

How to Submit Homework Assignments