[問題] ubbi dubbi翻譯程式

看板Programming作者 (獨在異鄉為異客)時間17年前 (2008/03/17 00:58), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/3 (看更多)
我在試著寫一個把英文翻成ubbi dubbi的程式 用的是python ubbi dubbi就是在英文字的第一個母音前加入ub 例如: hello -> hubello, apple -> ubapple, three -> threbee 我一開始寫的程式在翻譯一個單字時沒有問題 但在翻譯句子時就出現了麻煩 以下是我寫的程式 vowel = "aeiouAEIOU" inputline = sys.stdin.readline() inputwords = str.split(inputline) ubbiword = "" for word in inputwords: while word[0] not in vowel: ubbiword += word[0] word = word[1:] word = ubbiword + "ub" + word 可是這樣寫的話 會出現這樣的結果 today is sunday -> tuboday tubis tsubunday 我要怎麼樣才可以不讓第一個字母出現在每一個字前面呢? 先謝謝大家了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 69.143.181.102
文章代碼(AID): #17tL6Ykr (Programming)
文章代碼(AID): #17tL6Ykr (Programming)