Python練手專案0011

2021-07-25 23:48:31 字數 748 閱讀 7263

敏感詞文字檔案 filtered_words.txt,裡面的內容為以下內容,當使用者輸入敏感詞語時,則列印出 freedom,否則列印出 human rights。

# -*- coding: utf-8 -*-

"""created on thu jan 12 13:55:35 2017

@author: sky

"""def trans_to_words():

type_in = raw_input(">")

judge_flag = false

fout = open('reslut.txt','w')

with open('1.txt') as f:

text = f.read().decode('gbk').encode('gbk')

for i in text.split("\n"):

if i in type_in:

judge_flag = true

if judge_flag:

print "freedom"

fout.write('freedom')

else:

print "human rights"

fout.write('human rights')

fout.close

if __name__ == "__main__":

trans_to_words()

注意:裡面涉及到漢字轉碼,可以參考

詳細**和結果,可以參考

10個python練手專案

標記一下python的練手專案 10個python練手專案 python專案練習一 即時標記 python專案練習二 畫幅好畫 python專案練習三 萬能的xml python專案練習四 新聞聚合 python專案練習五 虛擬茶話會 python專案練習六 使用cgi進行遠端編輯 python專案...

10個Python練手專案

標記一下python的練手專案 10個python練手專案 python專案練習一 即時標記 python專案練習二 畫幅好畫 python專案練習三 萬能的xml python專案練習四 新聞聚合 python專案練習五 虛擬茶話會 python專案練習六 使用cgi進行遠端編輯 python專案...

python練手題目 Python練手題目(七)

1.計算重複字母出現的次數 編寫乙個函式,該函式將返回在輸入字串 現多次 不同的不區分大小寫的 字母字元和數字的計數。可以假定輸入字串僅包含字母 大寫和小寫 和數字。例如 abcde 0 no characters repeats more than once aabbcde 2 a and b a...