How to write a birthday greeting program in python?

Create a birthday greetings program using the following steps:

  1. Prompt the user to enter the name and age of the birthday person.
  2. Create a dictionary containing the name and age based on user input.
  3. Insert the birthday person’s name and age into the congratulatory message using string formatting.
  4. Print out the message of blessings.

Here is a simple example code:

def birthday_wish():
    name = input("请输入生日人的姓名: ")
    age = input("请输入生日人的年龄: ")

    birthday_person = {
        '姓名': name,
        '年龄': age
    }

    message = "祝福 {姓名} {年龄} 岁生日快乐!"

    print(message.format(**birthday_person))

birthday_wish()

After running the program, the user will be asked to input the birthday person’s name and age. Then, the program will print a birthday message similar to “Happy Birthday [Name] who is [Age] years old!”, with [Name] and [Age] being replaced by the name and age inputted by the user.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds