2019_8_1python
#函数
#函数是用来重复使用哒
#定义函数套路
'''
1、首先要会写出裸代码,然后看看哪里是重复需要使用的
2、接下来将需要重复使用的代码转换成参数,带入到函数中
函数格式
def funcName([param]):
执行体
[return]
函数调用
funcName()
'''
秒杀
def miaosha (user):
if user == 'vip':
print ('秒杀了')
else:
print ('没有秒杀')
print('检测是不是vip ')
miaosha('vip')
miaosha('bushivip')
商品有没有货
def shangpin(name):
if name == '2':
print('填写信息')
b = 0
a = input('姓名')
b = int(input('电话'))
jiancha(a,b)
else:
print('没货哦,不卖给你')
def jiancha(a,b):
if a != 'Joker' and b != 0:
print('立马出货')
else:
print('不卖给你')
b = input('输入要买啥 1、电脑 2、冰箱')
shangpin(b)
配送方位
def Check_Goods(g):
G = ['汽车','火车','飞机']
if g in G:
Address()
else:
print('没有这个货')
return False
def Check_Information(name,phone,Addr):
is_OK = True
if name == "" or name == " ":
print('用户名为空')
is_OK = False
if len(phone) != 11:
print('电话不对劲啊')
is_OK = False
if Addr not in ['北京','山东']:
print('不在配送范围')
is_OK = False
return is_OK
注册界面
import time
import random
import numpy as np
import string
def Check_User(username,password):
is_OK = True
A = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'
B = ',./;\'!@#$%^&*(_+|~'
C = '1234567890'
count1,count2,count3 = False,True,False
for i in username:
if i in A:
count1 = True
if i in B:
count2 = False
if i in C:
count3 = True
print(count1,count2,count3)
if count1 and count2 and count3:
print('OK')
else:
print('必须含有字母和数字,而且不能写特殊字符熬')
is_OK = False
if len(password) < 6:
print('必须6位以上')
return is_OK
def Check_Phone(phone):
is_OK = True
if len(phone) != 11:
print('电话不对劲啊')
is_OK = False
return is_OK
def Check_yzm():
is_OK = True
s = string.ascii_lowercase
start_time = time.time()
print('输入验证码,快输,10秒就过期了熬')
str1 = ""
for i in range(5):
for i in range(0,4):
a = random.choice(s)
b = np.random.choice([1,2,3,4,5,6,7,8,9,0])
c = random.choice([a,b])
print(c,end="")
str1 = str(str1)+str(c)
print('')
global_count += 1
shuru = input('请输入验证码,已经发了%d秒'%b)
time.sleep(1)
b += 1
end_time = time.time()
sub_time = end_time - start_time
if sub_time > 3:
if global_count > 2:
print('你是个机器人吧')
exit()
print('过期了熬,一会儿再给你一个熬')
time.sleep(5)
Check_yzm()
else:
if shuru == str1:
print('输对了')
break
else:
is_OK = False
print('不对哦')
return is_OK
def Login():
global global_count = 0
print('欢迎注册')
username = input('输入用户名')
password = input('输入密码')
res1 = Check_User(username,password)
if res1:
phone = input('输入电话')
res2 = Check_Phone(phone)
if res2:
res3 = Check_yzm()
if res1 and res2 and res3:
print('登陆成功')
Login()

浙公网安备 33010602011771号