1、今天学习了函数,相比前几天状态好了一丢丢。。。。

------------------------我是分割线-------------------------------------------------

2、以下是众多的栗子----

#函数是用来重新使用的。
#定义函数
""" 1、首先要写出裸代码,看看那些是需要重复使用的 2、接下去将需要重复使用的代码转换成参数,带入到函数中 def funcName([param]): 执行体 [return]
调用: funcName() """ def liyuan(): print('Hello world') liyuan()
def liyuan(input_): print('%s 你真帅'%input_) liyuan('李媛')
#一件商品,两个人同时秒杀,办理vip的能抢到 def H(a): b=['liyuan'] if a in b: print('恭喜') else: print('很遗憾,你与大奖擦肩而过,但是不要灰心,继续努力') #python中一切函数都有返回值,如果无参数就是返回none #三个函数,依次运行,从第一个开始如果中途不满足条件退出 #1.检测是否有货 2.填地址 3.发货 def Check_Goods(g): ku=['泡面','香蕉','水果'] if g in ku: Address() else: return False
def Address(): address=input('input your address:') phone=input('input your phone:') name=input('input your name:') res=Check_Information(address,phone,name) if res:
Note() return False def Check_Information(address,phone,name): is_ok=True if name =="" or name == " ": is_ok=False if len(phone) !=11: is_ok=False if address not in ['北京','山东']: is_ok=False return is_ok def Note(): print('马上发货')
def Start(): print('欢迎光临') g=input('商品:') Check_Goods(g) Start() #用户注册 global global_count==0 def Users(): name=input('输入用户名:') z='qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM' s='1234567890' t='*&^%$#@!' is_z=False is_s=False is_t=True for i in name:   if i in z:     is_z=True    if i in s:      is_s=True   if i in t:      is_t=False if(is_z and is_s and is_t): Paasword() else:    print('用户名输入不合法,必须含有数字和字母且不能还有特殊字符')
def Paasword(): password=input('请输入密码:') if len(password) != 6:    print('不合法') else: Phone() def Phone(): phone=input('请输入电话号码:') # if len(phone) != 11: # print('不合法') phonecheck() else: print('验证码已发送') verify_number()
def verify_number(): global global_count import random import time num=random.randrange(1000,9999) global_count +=1 start_time=time.time() print('验证码为:%d'%num) for i in range(11): print((11-i)) time.sleep(1) num_=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) verify_number() else: if num == num_: print('注册成功') else: print('验证码错误') def Start(): Users() 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: print('验证码超时,即将重发..') time.sleep(2) Verfily_number() else: if num == num_: print('注册成功') else: print('验证码错误') def Start(): Users() Start() def add(*args): sum_==0 if len(args) == 0: print('无效数字!') else: for i in args: sum_ += i print(sum_) add(1,2,34,,5,6) 匿名函数 (lambda x:print(x+x))(100)

 



 

posted on 2019-08-01 16:17  TheNerverLemon  阅读(178)  评论(2编辑  收藏  举报