列表之
隨機密碼生成。編寫程序,在26個字母大小寫和9個數字組成的列表中隨機生成10個8位密碼。app
1 from random import randint#導入random庫 2 ls = []#定義一空列表 3 def use(n,x):#自定義函數 4 for i in range(n,x): 5 ls.append(chr(i)) 6 use(97,123)#調用函數97,123,65等爲ASCII碼 7 use(65,91) 8 use(48,58) 9 s = 0 10 while s<10:#輸出是個隨機密碼 11 mi = '' 12 s += 1 13 for j in range(8): 14 index = randint(0, 61) 15 mi = mi + ls[index] 16 print("第{}個密碼是{}".format(s,mi))
運行結果爲dom