CSC111 Homework 5 2015

From dftwiki3
Revision as of 10:12, 24 February 2015 by Thiebaut (talk | contribs) (Requirements)
Jump to: navigation, search

--D. Thiebaut (talk) 09:55, 24 February 2015 (EST)


Problem #1


  • Write a program called hw5_1.py that asks the user for the name of a person to sing "Happy Birthday" to, and then displays the song in a box 52-characters wide.


Example output


Who should we sing for? Carl
+--------------------------------------------------+
|              Happy birthday to you!              |
|              Happy birthday to you!              |
|            Happy birthday, dear Carl!            |
|              Happy birthday to you!              |
+--------------------------------------------------+


Requirements


  • This should be the outline of your program:


# hw5_1.py
# your name
# short description
def happyBirthday():
    ...

def happyBirthdayDear( name ):
    ...

def singSong( name ):
    ...

def main():
    ...

main()


  • Make sure you use the same function names as shown above, with the same parameter name. The test script will look for the same format.


Submission to Moodle


  • Submit your program in the HW5 PB 1 section on Moodle.


Problem #2


Modify your program, while still keeping the same organization (with some modifications, see below), so that the box is tight around the song, as illustrated below:

Example output 1


Who should we sing for? Lu
+------------------------+
| Happy birthday to you! |
| Happy birthday to you! |
|Happy birthday, dear Lu!|
| Happy birthday to you! |
+------------------------+


Example output 2


Who should we sing for? Alexandra-Katarina
+----------------------------------------+
|         Happy birthday to you!         |
|         Happy birthday to you!         |
|Happy birthday, dear Alexandra-Katarina!|
|         Happy birthday to you!         |
+----------------------------------------+


Requirements


  • Your program should now have the following organization, where a new parameter is being passed to the functions. This parameter is the length of the line with the user name, inside the box.


# Hw5_2.py
# Your name
# short description

def happyBirthday( length ):
    ...

def happyBirthdayDear( name, length ):
    ...

def singSong( name, length ):
    ...

def main():
    ...

main()


Submission


  • Name your program hw5_2.py and submit it to Moodle, Section HW 5 PB 2.


Problem #3


Modify your previous program and make it accept several names as an input:

Example output


Who should we sing for? 
(you may enter several names separated by spaces)
> Carl Jorge Gru Minions
+--------------------------+
|  Happy birthday to you!  |
|  Happy birthday to you!  |
|Happy birthday, dear Carl!|
|  Happy birthday to you!  |
+--------------------------+

+---------------------------+
|   Happy birthday to you!  |
|   Happy birthday to you!  |
|Happy birthday, dear Jorge!|
|   Happy birthday to you!  |
+---------------------------+

+-------------------------+
|  Happy birthday to you! |
|  Happy birthday to you! |
|Happy birthday, dear Gru!|
|  Happy birthday to you! |
+-------------------------+

+-----------------------------+
|    Happy birthday to you!   |
|    Happy birthday to you!   |
|Happy birthday, dear Minions!|
|    Happy birthday to you!   |
+-----------------------------+


Requirements


  • Your program should have the following organization as for Problem 2.


# Hw5_3.py
# Your name
# short description

def happyBirthday( length ):
    ...

def happyBirthdayDear( name, length ):
    ...

def singSong( name, length ):
    ...

def main():
    ...

main()


Submission


  • Name your program hw5_3.py and submit it to Moodle, Section HW 5 PB 3.