
TQC+ 程式語言Python 806 字元次數計算
題目說明:
請撰寫一程式,讓使用者輸入一字串和一字元,並將此字串及字元作為參數傳遞給名為compute()的函式,此函式將回傳該字串中指定字元出現的次數,接著再輸出結果。
範例輸入
Our country is beautiful
u
範例輸出
u occurs 4 time(s)
程式碼:
def compute(Str, s):
return Str.count(s)
Str = input()
s = input()
print('%s occurs %d time(s)' %(s, compute(Str, s)))
TQC+ 程式語言Python 第8類:字串(String)的運作
如果覺得文章內容還不錯的話,麻煩請幫我點個讚!感謝
可以多點幾次喔~~
第一次點讚需使用 Google 或 Facebook 帳號註冊

