Day 22 - Python

Birthday Special!

Problem Statement

You are tasked with organizing a birthday party every year for a person, aged from 1 to 100. The following conditions must be met for each birthday:

  1. Candles: The number of candles increases exponentially each year. Specifically, the number of candles for year n is given by 
    2(n1)

  2. Balloons: The number of balloons increases in multiples of 10 each year. Specifically, the number of balloons for year n is 
    10×n

  3. Gifts: The number of gifts is double the age. Specifically, the number of gifts for year n is 
    2×n

  4. Leap Year Bonus: If the current year is a leap year, you will also:

    • Select a cake flavor randomly from a list of 10 flavors.
    • Double the number of candies given, which is based on the last two digits of the year. If the year is 2024, give 48 candies (since the last two digits are 24).                                                
  5. Cake Flavors: The available cake flavors are: Chocolate, Butterscotch, Red Velvet, Rasmalai, White Forest, Mango, Choco Truffle, Caramel, Ferrero Rocher, and Black Currant.
  6. Output: For each birthday, print the cake flavor (if it’s a leap year), number of candles, number of balloons, number of gifts, and number of candies (if it’s a leap year).

Input

  • Age of the person (from 1 to 100).
  • Current year.

Output

Print the cake flavor (if it’s a leap year), number of candles, number of balloons, number of gifts, and number of candies (if it’s a leap year).

Test Cases

Below are five test cases with the corresponding solutions.

Test Case 1

Input:

Age: 18; Year: 2024

Output:

  • Number of candles: 33554432
  • Number of balloons: 260
  • Number of gifts: 52
  • Cake flavor: (random from a list of 10 flavors, e.g., "Ferrero Rocher")
  • Number of candies: 48

Test Case 2

Input:

Age: 10; Year: 2023

Output:

  • Number of candles: 512
  • Number of balloons: 100
  • Number of gifts: 20

Test Case 3

Input:

Age: 15; Year: 2028

Output:

  • Number of candles: 16384
  • Number of balloons: 150
  • Number of gifts: 30
  • Cake flavor: (random from a list of 10 flavors, e.g., "Rasmalai")
  • Number of candies: 56

Test Case 4

Input:

Age: 5; Year: 2022

Output:

  • Number of candles: 16
  • Number of balloons: 50
  • Number of gifts: 10

Test Case 5

Input:

Age: 100; Year: 2100

Output:

  • Number of candles: 633825300114114700748351602688
  • Number of balloons: 1000
  • Number of gifts: 200
PS: Candles count is hypothetical! Created only for the Program Aspect 
Output Order: Candles, Balloons, Gifts, [Cake, Candies]

SOLUTION

import random

def isLeapYear(year):
    return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)

def birthdayCelebration(age, year):
    flavors = ["Chocolate", "Butterscotch", "Red Velvet", "Rasmalai", "White Forest", "Mango", "Choco Truffle", "Caramel", "Ferrero Rocher", "Black Currant"]
    
    candles = 2 ** (age - 1)
    balloons = 10 * age
    gifts = 2 * age
    
    print(f"Number of candles: {candles}")
    print(f"Number of balloons: {balloons}")
    print(f"Number of gifts: {gifts}")
    
    if isLeapYear(year):
        flavor = random.choice(flavors)
        temp = year % 100
        candies = temp * 2
        
        print(f"Cake flavor: {flavor}")
        print(f"Number of candies: {candies}")


age = int(input())
year = int(input())

if(age>0 and age < 101):
    birthdayCelebration(age, year)


INSIGHTS

1. The number of candles grows exponentially. For example, at age 10, the number of candles is 29=. By age 20, it is 219=. This rapid growth illustrates the concept of exponential increase.

2. The number of balloons increases linearly, at a rate of 10 balloons per year of age. For example, at age 5, there are 50 balloons, and at age 10, there are 100 balloons. This straightforward linear increase is easy to calculate and predict.

3. The number of gifts is always double the age. For example, at age 8, there are 16 gifts, and at age 25, there are 50 gifts. This simple doubling makes it easy to understand and calculate the number of gifts.

4. The number of gifts is always double the age. For example, at age 8, there are 16 gifts, and at age 25, there are 50 gifts. This simple doubling makes it easy to understand and calculate the number of gifts.

5. The number of gifts is always double the age. For example, at age 8, there are 16 gifts, and at age 25, there are 50 gifts. This simple doubling makes it easy to understand and calculate the number of gifts.

6. In leap years, the number of candies is determined by the last two digits of the year, multiplied by 2. For instance, in the year 2024, the last two digits are 24, resulting in 48 candies. This adds an interesting numeric twist to the celebration.

7. In leap years, the number of candies is determined by the last two digits of the year, multiplied by 2. For instance, in the year 2024, the last two digits are 24, resulting in 48 candies. This adds an interesting numeric twist to the celebration.

8. The program can handle large numbers gracefully. For example, the number of candles for age 100  is 299, which is a very large number, but Python handles it seamlessly due to its ability to manage big integers. 

9. The program works well for the edge cases of age 1 (1 candle, 10 balloons, 2 gifts) and age 100 (a very large number of candles, 1000 balloons, 200 gifts). This shows that the program is robust and can handle the full range of ages from 1 to 100.

10. This program can be used as an educational tool to demonstrate concepts such as exponential growth, linear growth, conditional logic, random selection, and handling user input. It provides practical examples of how these concepts can be applied in programming.


This post is dedicated to everyone all around the world celebrating their birthdays!!
"May your special day be filled with joy and surprises, just like a perfectly coded birthday celebration!" 🕯️🎈🎁🎂🍬
Happy Birthday and Happy Coding!

Comments