CSC111 Homework 5 2015
--D. Thiebaut (talk) 09:55, 24 February 2015 (EST)
Contents
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
Who should we sing for? Lu +------------------------+ | Happy birthday to you! | | Happy birthday to you! | |Happy birthday, dear Lu!| | Happy birthday to you! | +------------------------+ 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.