(1)编写程序,给出一个英文句子,统计单词个数。
xiaofeng = input("请输入英文句子:")
words = xiaofeng.split( )
print("单词个数为:", len(words))
Python中超好用的split()函数,详解_python split_捣鼓Python的博客-CSDN博客
(2)编写程序,给出一个字符串,将其中的字符“E”用空格替换后输出。
s = input("请输入字符串:")
s = s.replace("E", " ")
print("替换后的字符串为:",s)
python replace 方法_小云从0学算法的博客-CSDN博客
(3)从键盘交互式输入一个人的18位的身份证号,以类似于“2001年09月12日”的形式输出该人的出生日期。
d_card = input("请输入身份证号:")
birth_year = int(id_card[6:10])
birth_month = int(id_card[10:12])
birth_day = int(id_card[12:14])
# birth_date = datetime.date(birth_year, birth_month, birth_day)