Python file exercise_generate mobile phone number

need:

1. First randomly generate some mobile phone numbers starting with 1861031XXXX
2. Write to the file

accomplish:

import random
f = open('phone.txt','w')
num = input( ' Please enter the number of mobile phone numbers you want to generate ' )
 for i in range(int(num)):
    start = ' 1861031 ' 
    end = random.randint(1,1000) #Randomly generate numbers from 1 to 1000 
    end_s = str(end).zfill(4) #Specify four digits, if less than four digits are filled with zeros 
    phone = start+end_s+ ' \n '
    f.write(phone)
f.close() #If the file is opened, it must be closed

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325257203&siteId=291194637