我自己做了一个随机生成手机号的代码练习,但是在生成手机号的过程中,后面8位数的首位为0时会自动删减,求大佬帮忙指教一下。
代码如下:
import random
def Suijihaoma(num):
a=[133,134,149,153,170,177,180,181,189,130,131,132,145,155,170,175,176,185,186,134,135,136,137,138,139,147,150,151,152,157,158,159,178,182,183,184,187,188]
d=[0,1,2,3,4,5,6,7,8,9]
e=[]
q=[]
g=random.choice(a)
for i in range(8):
e.append(random.choice(d))
print(e)
l = str(e).replace("[","").replace("]","").replace(",","").replace(" ","")
m=(g,int(l))
n=str(m).replace(' ','').replace('(','').replace(')','').replace(',','')
return n
haoma=Suijihaoma('x')
print(haoma)