python随机产生8位密码,密码由数字和字母组成

import random

digits = [chr(i) for i in range(48, 58)]
letters = [chr(i) for i in range(65, 91)] + [chr(i) for i in range(97, 123)]

number_of_digits = random.randint(1, 7)
number_of_letters = 8 - number_of_digits
randdigits = [random.choice(digits) for i in range(number_of_digits)]
randletters = [random.choice(letters) for i in range(number_of_letters)]
randdigits.extend(randletters)
random.shuffle(randdigits)
print(''.join(randdigits))

你可能感兴趣的:(python,开发语言)