1. 输入一行字符,统计其中有多少个单词,每两个单词之间以空格隔开。如输入: This is a c++ program. 输出:There are 5 words in the line. 【考核知识点:字符串操作】
a = input()
b = a.split(' ')
num = len(b)
print("There are %d words in the line" %(num))
2. 给出一个字符串,在程序中赋初值为一个句子,例如"he threw three free throws",自编函数完成下面的功能:
1)求出字符列表中字符的个数(对于例句,输出为26);
a = input()
num = len(a)
print("There are %d words in the line" %(num))
2)计算句子中各字符出现的频数(通过字典存储); ---学完字典再实现