How to write a birthday greeting program in python?
Create a birthday greetings program using the following steps:
- Prompt the user to enter the name and age of the birthday person.
- Create a dictionary containing the name and age based on user input.
- Insert the birthday person’s name and age into the congratulatory message using string formatting.
- 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.