欢迎访问宙启技术站
智能推送

用Python编写红色主题的生日贺卡程序

发布时间:2023-12-27 22:46:39

以下是一个使用Python编写的红色主题的生日贺卡程序的代码示例:

import time

def print_card(name):
    print('*' * 30)
    print(' Happy Birthday, {}!'.format(name))
    print('*' * 30)
    print('
')
    print('Wishing you a day filled with love, joy, and happiness!')
    print('May all your dreams and wishes come true!')
    print('
')
    print('With warmest regards,')
    print('Your Name')
    print('
')
    print('*' * 30)
    print('
')

def main():
    print('==== Birthday Card Generator ====')
    print('
')
    name = input('Enter the recipient\'s name: ')
    
    while True:
        print('
')
        print('1. Generate birthday card')
        print('2. Exit')
        choice = input('Select an option (1-2): ')
        
        if choice == '1':
            print_card(name)
        elif choice == '2':
            print('Goodbye!')
            break
        else:
            print('Invalid option. Please try again.')
        
        time.sleep(2)

if __name__ == '__main__':
    main()

使用例子:

==== Birthday Card Generator ====

Enter the recipient's name: Jane


1. Generate birthday card
2. Exit
Select an option (1-2): 1
******************************
 Happy Birthday, Jane!
******************************


Wishing you a day filled with love, joy, and happiness!
May all your dreams and wishes come true!


With warmest regards,
Your Name


******************************

1. Generate birthday card
2. Exit
Select an option (1-2): 2
Goodbye!

以上代码实现了一个简单的红色主题的生日贺卡程序。用户可以输入收件人的姓名,并选择生成生日贺卡或退出程序。生成的生日贺卡会打印在终端上,包括收件人的姓名和祝福语。在代码中,使用了time.sleep(2)来模拟程序的运行过程,以便用户能更好地观察输出结果。