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.

字符串是沒有下標的,所以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))


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM