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)

Comments are closed.