# -*- coding: utf-8 -*-
"""
@author:lyf
@file:test_random_other_demo.py
@date:06/21 18:32
"""
import random
import string
def test_phone_PWD():
a =["137","157","186"]
#随机生成 137 157 186开头的手机号
phone=random.choice(a)+str(random.randint(10000000,99999999))
print(phone)
#string.ascii_letters 随机生成字母 string.digits随机生成0-9的数字
P=string.ascii_letters+string.digits
length=random.randint(8,20)
print(length)
#string.join 字符串拼接 random.sample(str,length)
PWD="".join(random.sample(P,length))
print(PWD)
print(phone+","+PWD)
def test_str_demo():
a="测试"
b="测试,工程师"
a2=b.split(",")[0]
a3=b.split(",")
print(a,a2,a3)
print (a,'\n',a2,'\n',a3,'\n')
print("我是换行\n换行啦1111111")
print("000000000000")
print(id(a),id(a2))
print(id(a)==id(a2))
print(a==a2)
#终止所有循环break 和 终止本次循环continue
def test_renge_demo():
for i in range(5):
if i ==4:
break
print(i)
for i in range(10,17):
if i ==15:
continue
print(i)
def continue_demo():
a=0
while a < 5:
print(a)
if a == 3:
a+=1
continue
print(f'循环到第{a+1}次')
a+=1
def break_demo():
a= 0
while a < 4:
print(a,'\n',f"循环到第{a+1}次")
if a ==3:
break
a+=1
#while demo
def while_demo():
a=0
while a <= 5:
#如果条件满足 a<= 5 就一直循环,直到条件不满足 终止循环
print(a)
a+=1
#set()函数 去重,1.会把列表类型转变为set函数, 2.会从大到小排序
#list去重
def distenct():
alist=[3,2,1,5,1,4.5]
print("alist="+str(alist))
blist=[]
for i in alist:
if i not in blist:
blist.append(i)
print(blist)
#去重方式2
s=[]
s=set(alist)
print(s)
#for循环demo 嵌套循环 内循环外循环
def for_demo():
for i in range(5):
print(f"外循环第{i}次")
for j in range(3):
print(f" 内循环第{j}次")
#list 转字典 ,list的索引作为key,list的值作为value
def list2dict():
alist=['yi','er','san']
adict={}
for i in range(len(alist)):
#for 循环 取alist的长度,i分别作为dict和list的下标 取alist[i]的值赋给adict[i]
adict[i]=alist[i]
print(alist,'\n',adict)
#猜数游戏 :计算机随机给0-100的数,人为输入数字比大小,计算机给出对应的大小提示,直到猜对,并打印猜的次数
def guss_number():
answer =random.randint(0,100)
print(answer)
conter =0
while True:
conter+=1
number=int(input('请输入数字:'))
if number < answer:
print("大一点")
elif number > answer:
print('小一点')
else:
print('恭喜你猜对了')
break
print(f'总共猜了{conter}次')
if __name__ == '__main__':
break_demo()