Programming 102 Week 1 Challenges (Python)

Python function to display Happy Birthday

In originally planned to do one blog entry for all the Programming 102 course (see: https://geektechstuff.com/2019/01/21/programming-102-think-like-a-computer-scientist-python-raspberry-pi/) but due to the amount of coding tasks/challenges (which is great) I’ve going to do one for each week and possibly one for the end of week challenges.

Week 1

Challenge 2: “Create a function with one parameter, name, which will be the name of a person. The function should then “sing” Happy Birthday to that person, inserting their name at the correct point. Give your function a sensible name.

# geektechstuff
# Happy Birthday

import time

def happy_birthday(name):
name = name.capitalize()
for x in range(2):
print(‘Happy Birthday to you.’)
time.sleep(1)
print(‘Happy Birthday to’,name,’!’)
time.sleep(1)
print(‘Happy Birthday to you.’)
time.sleep(1)
for x in range(3):
print(‘Hip Hip Hooray!’)

happy_birthday(‘gary’)

Python function to display Happy Birthday
Python function to display Happy Birthday

I’ve used the sleep() function from the time module so that the Birthday message doesn’t display instantly.

One thought on “Programming 102 Week 1 Challenges (Python)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.