python第三天

#函数是用来重复使用的 #定义函数有套路 ''' 1.首先要会写出裸代码,然后将重复使用的代码转换成参数 2.带入函数 ''' ''' def funcName([param]): 执行体 [return] ''' ''' 调用 funcName() ''' ''' def Joker(): print('Hello wodr') # print(Joker) if Joker ''' ''' def Joker(input_): print('%s你真帅'%input_) Joker('Joker') ''' ''' def A(kehu): b = ['vip'] if kehu in b: print('抢到了') else: print('很遗憾') A("23") ''' ''' def Check_Goods(g): G = ['小花','大花','霸王花'] if g in G: Address() else: return False def Check_Information(name,phone,Addr): is_OK = True if name == "" or name == " ": is_OK = False if len(phone) != 11: is_OK = False if Addr not in ['北京','山东']: is_OK = False return is_OK def Address(): name = input('姓名:') phone = input('电话:') Addr = input('地址:') res = Check_Information(name,phone,Addr) if res: Note() return False def Note(): print('马上发货') def Start(): print('欢迎光临') g = input('输入要购买的商品:') Check_Goods(g) Start() #启动函数 ''' ''' def Zhuce1(): users = input('用户名:') passwodr = input('密码:') phone = input('电话:') res = zhuce2(users,passwodr,phone) if res: zhuce3() return False def zhuce2(users,passwodr,phone,): Z = ['ZXCVBNMASDFGHJKLQWERTYUIOP'] N = ['0123456789'] T = ['、*-+'] is_OK = True if users == "" or users == " " or user != Z or users !=N or users == T: is_OK = False print('用户名格式错误,用户名必须为大写字母和数字且不能还有特殊字符') if len(passwodr) <= 6: is_OK = False print('密码格式错误,密码必须大于6位') if len(phone) != 11: is_OK = False print('电话格式错误') return is_OK def Verfily_number(): import random num = random.randrange(1000,9999) print('验证码为 :') num_ = input('输入验证码 :') def zhuce3(): print('注册成功') def Start(): print('欢迎光临') Zhuce1() Start() ''' ''' def Users(): users_ = input('Users:>>') # Joker123 Z = 'ZXCVBNMASDFGHJKLQWERTYUIOPzxcvbnmasdfghjklqwertyuiop' N = '1234567890' T = '.*&^%$#@!~' is_Z = False is_N = False is_T = True for i in users_: # 字母 if i in Z: is_Z = True # 数字 if i in N: is_N = True # 特殊字符 if i in T: is_T = False if is_Z and is_N and is_T: Password() else: print('账号必须含有数字和字母且不能含有(.*&^%$#@!~)') def Password(): passwd = input('请输入密码:>>') if len(passwd)<6: print('密码必须大于6位') else: Phone() def Phone(): phone = input('请输入电话号码:>>') if len(phone) != 11: print('亲,电话号码无效') else: print('验证码已发送') Verfily_number() def Verfily_number(): import random import time num = random.randrange(1000,9999) start_time = time.time() print('东方智业文化发展有限公司给予您的验证码是:%d'%num) num_ = int(input('请输入验证码:')) end_time = time.time() sub_time = end_time - start_time if sub_time > 10: if global_count >2: print('你可能是个机器人.') exit() print('验证码超时,即将重发..') #time.sleep(2) Verfily_number() else: if num == num_: print('注册成功') else: print('验证码错误') time.sleep(2) Verfily_number() def Start(): Users() Start() ''' ''' def add(*args): if len(args) !=0: print('无效数字') else: for i in args: sum_+=i print(sum_) add(1,2,3,4,5,6,7,8,9) ''' ''' (lambda x,a:print(x+a))(100,5) ''' ''' def zhengxu1(): res = zhuce2() if res: zhuce3() return False def chengxu2(zhengshu,fushu,sum_,cishu,data): while data !=0 : data = eval(input(">>")) if data > 0: zhengshu += 1 print(zhengshu) if data < 0: fushu += 1 sum_ += data print(fushu) if data != 0: cishu += 1 print(sum_ / cishu) ''' ''' def chengxu1(zhengshu,fushu,sum_,cishu,data): while data !=0 : data = eval(input(">>")) if data > 0: zhengshu += 1 if data < 0: fushu += 1 sum_ += data if data != 0: cishu += 1 else: break print(zhengshu) print(fushu) print(sum_ / cishu) zhengshu = 0 fushu = 0 sum_ = 0 cishu = 0 data = 1 chengxu1(zhengshu,fushu,sum_,cishu,data) ''' ''' def yunxing(zhengshu,fushu,sum_,cishu,data): while data !=0 : data = eval(input('输入一个整数>>')) if data > 0: zhengshu += 1 if data < 0: fushu += 1 sum_ += data if data != 0: cishu += 1 else : break print(zhengshu) print(fushu) print(sum_ / cishu) zhengshu = 0 fushu = 0 sum_ = 0 cishu = 0 data = 1 yunxing(zhengshu,fushu,sum_,cishu,data) ''' ''' def F(x,y): count = 0 for i in range(x,y): if i %5 == 0 and i %6 ==0: print(i,end=" ") count +=1 if count % 10 == 0: print() F(100,1001) ''' ''' def D(n): while 1: res = n ** 2 if res >= 12000: break else: n += 1 print(n) D(0) ''' ''' def rs(Money,lilv) nian = 5 for i in range(24): M = Money * lilv / 100 T = 12 * M * nian print(lilv,'%','月利率',M,'总和',T) if lilv == 5.25: print('.....') lilv += 1/8 ''' ''' def shang(): import math print('enter ten numbers:') ls=[] sum1=0.0 devi=0.0 for i in range(10): num=eval(input('')) ls.append(num) part1=0.0 part2=0.0 for i in range(10): sum1=sum1+ls[i] mean=sum1/10 for i in range(10): part1=part1+(ls[i]-mean)**2 #part2=sum1**2 #print(part1,part2) devi=math.sqrt(part1/9) print('The mean is %.2f'%(mean)) print('The standerd deviation %f'%(devi)) shang() ''' def D(x): a = 0 for i in range(1,8,2): for j in range(2,8): if i != j: print(i,j) a += 1 print(a) D(7)
posted @ 2019-08-01 20:34  老了杜杜  阅读(149)  评论(0编辑  收藏  举报