我已經在python 3.4中編寫了一個簡單的詞表生成器,我還在學習,所以它不是最好的代碼,但我只是想更深入和理解語言和它的邏輯,首先這裏是我的代碼:在Python 3.4中增強我的代碼(Wordslist生成器)
import random
letters = ['a','b','c','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0']
wordslist = []
def Generate_words(_from,_to,_length):
while _from <= _to:
random_word = _length*random.choice(letters)
if (random_word) in (wordslist):
print ("Word already exists, looking for another one..")
else:
wordslist.append(random_word)
print ("total of "+str(_from)+" generated word(s) added to wordlist..")
progress = _from/_to*100
print ('total progress is: '+str(progress)+'%')
_from = _from+1
if _from > _to:
print ("Wordslist generated: ")
print (wordslist)
Fnumber = input ("Enter the total number of words you want to generate: ")
Snumber = input ("Enter the length of each word: ")
Generate_words(1,int(Fnumber),int(Snumber))
Exit = input("Press any key to exit")
現在我知道,這條線:random_word = _length * random.choice(字母)會產生相同的字母X號,這是第一個問題,我正在努力解決。 我試圖做的第二件事是找到一種方法,防止腳本生成一個以前生成的單詞,這將使它更快,更高效
這正是我所期待的。感謝您的回覆,非常感謝 – q8mind 2014-10-07 19:55:22