#需求分析:
#1, first three bits OK, can define a list, such as Lis = [' 131 ', ' 132 ', ' 133 ', ' 134 ', ' 135 ', ' 136 ', ' 137 ', ' 138 ', ' 139 ', ' 158 ', ' 159 ', ' 185 '
#2, trailing eight-bit random fetch, via Random.sample (str,8)
Add phone number with list:
def phone_num (num):
Import random,string
all_nums = []
For i in range (num):
lis = [' 131 ', ' no ', ' 133 ', ' 134 ', ' 135 ', ' 158 ', ' 159 ', ' 185 ', ' 186 ', ' 188 ']
start = Random.choice (LIS)
end = '. Join (Random.sample (string.digits, 8))
res = start + end + ' \ n '
if res not in All_nums:
all_nums.append (RES)
With open (' Telephone.txt ', ' W ', encoding= ' UTF8 ') as FW:
fw.writelines (all_nums)
Phone_num (10)
Add a phone number with a collection:
def phone_num (num):
Import random,string
all_phone_nums = set ()
Num_start = [' 134 ', ' 135 ', ' 136 ', ' 137 ', ' 138 ', ' 139 ', ' a ', ' 151 ', ' a ', ' 158 ', ' 159 ', ' 157 ']
For i in range (num):
start = Random.choice (Num_start)
end = '. Join (Random.sample (string.digits,8))
res = start + end + ' \ n '
All_phone_nums.add (RES)
With open (' Phone.txt ', ' w ', encoding = ' UTF8 ') as FW:
fw.writelines (all_phone_nums)
Phone_num ()
Day6_ randomly generated 11-digit mobile phone number program