#Python TQC考題806 字元次數計算
def compute(s,c):return
#只因題目指定需def compute()
#實際不需要此行
s=input()
c=input()
cnt=s.count(c)
#計算c在s中出現了幾次
print(“%s occurs %d time(s)” %(c,cnt))

#題目希望的寫法:
def compute(s,c):return s.count(c)
s=input()
c=input()
print(“%s occurs %d time(s)” %(c,compute(s,c)))


def compute(sent,word):
return sent.count(word)
sent=input()
word=input()
print(word,”occurs”,str(compute(sent,word)),”times(s)”)
#字串間用逗點分隔,自動生出空白
#用+連接,沒有空白


#string就可以.count()了
#不用轉成list,多此一舉了!







![Python TQC考題910 學生基本資料, print(line.decode(“utf-8”)), if line.decode(“utf-8″).split()[2] ==”0”: female += 1 Python TQC考題910 學生基本資料, print(line.decode(“utf-8”)), if line.decode(“utf-8″).split()[2] ==”0”: female += 1](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/05/20220514163621_72.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python list[] dictionary{key: value},如何從兩個list,建立一個dictionary? Python list[] dictionary{key: value},如何從兩個list,建立一個dictionary?](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220904074100_2.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言