Python-产生手机号码

# 写一个随机产生138开头手机号的程序
#         1、输入一个数量,产生xx条手机号
#             prefix = '138'
#         2、产生的这些手机号不能重复

import random,string

number = set()
num = input('请输入需要产生多少条手机号码:').strip()

if num.isdigit():
    while len(number)!= int(num):
        p =str(random.randint(10000000,99999999))
        phone = '138'+ p + '\n'
        number.add(phone)
else:
    print('请输入数字')

with open('phones.txt','a+')as fw:
    fw.writelines(number)

猜你喜欢

转载自www.cnblogs.com/brf-test/p/12951023.html