PTA的Python练习题(八)

 第3章-15 统计一行文本的单词个数 继续

1.

 

s = input()
count=0
for c in s:
    if c==' ':
        count=count+1
    if c=='.':
        break
print(count+1)

 

2.

字符串是没有下标的,python里面也没有数组,所以C语言常用的冒泡法这里不能用

a=input()
b=''
for i in a:
    if i not in b:
        b=b+i
c=list(b)
c.sort()
d=''.join(c)
print(d)

所以这里用了很多强制类型转换,此外排序sort()函数只能用在list列表上,也需转换

知识点:

 

3.

笨办法做题目:替换空格,再用空列表接收除了E的大小写以外的字符串

知识点:

a=input()
b=a.replace(' ','')
c=input()
c1=c.lower()
c2=c.upper()
d=''
for i in b:
if i not in c1:
if i not in c2:
d=d+i
print('result: {}'.format(d))

猜你喜欢

转载自www.cnblogs.com/echoDetected/p/12294554.html