import random
'''
手機號的規則如下
第一位:1;
第二位:3,4,5,7,8
第三位:
3:0-9
4:5,6,7
5:0,1,2,3,5,6,7,8,9
7:6,7,8
8:0-9
'''
def telphone():
second = random.choice([3,4,5,7,8])#第二位值,從此列表隨機生成
third = {
3:random.randint(0,9),
4:random.choice([5,7]),
5:random.choice([0,1,2,3,5,6,7,8,9]),
7:random.choice([6,7,8]),
8:random.randint(0,9)
}[second]#根據second的值,來生成第3位的值
behind = ''#定義個空字符串
for i in range(8):
behind = behind + str(random.randint(0,9))#8位數字中的每一位從0-9中生成,8次循環后,字符串相加成為8位數
phone_number = str(1) + str(second) + str(third) + behind#四組字符相加,生成手機號
print(phone_number)
return phone_number
for i in range(10):
telphone()#調用生成手機號函數
