import random code = [] for i in range(6): if i == random.randint(1,5): code.append(str(random.randint(0,9))) else: temp = random.randint(65,90) code.append(chr(temp)) print ''.join(code)