Programming 102 Week 1 Challenges (Python)

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 response to “Programming 102 Week 1 Challenges (Python)”

Welcome to GeekTechStuff

my home away from home and where I will be sharing my adventures in the world of technology and all things geek.

The technology subjects have varied over the years from Python code to handle ciphers and Pig Latin, to IoT sensors in Azure and Python handling Bluetooth, to Ansible and Terraform and material around DevOps.

Let’s connect