ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

day0203

2019-08-01 21:03:10  阅读:252  来源: 互联网

标签:%. False day0203 2f time print input


 

day02

1.for i in range() --->用于设置for循环的迭代设置。
ranage 也是一个前闭后开的。

2.random.randrange() --->随机产生给予范围之内的随机数字
random.randrange(1000,9999)

day03


1.python的缺点 精度丢失

 

1.例题

#密码包含大小写和数字 username = input('请输入用户名:') password = input('请输入密码:') A ='qwertyuiopasdfghjklzxcvbnm' B ='QWERTYUIOPASDFGHJKLZXCVBNM' C ='1234567890' count1,count2,count3 = False,False,False for i in password:   if i in A :   count1 = True   if i in B :   count2 = True   if i in C :   count3 = True if count1 and count2 and count3 :   print('注册成功') else :   print('密码必须含有大写,小写和数字')

2.例2

#输入两个数字进行加减乘除 num1,num2 = map(float,input('请输入Num1和Num2:').split(',')) choose_method = input('Choose Method:[+,-,*,/]')   if choose_method in '+-*/':     if choose_method == '+':       print('%.2f + %.2f = %.2f'%(num1,num2,num1+num2))     elif choose_method == '-':       print('%.2f - %.2f = %.2f'%(num1,num2,num1-num2))     elif choose_method == '*':       print('%.2f * %.2f = %.2f'%(num1,num2,num1*num2))   elif choose_method == '/': print('%.2f / %.2f = %.2f'%(num1,num2,num1/num2))     else:     #抛出错误     raise KeyError('Only choose [+,-,*,/]')  

 

3.例3

#三次输入错误密码锁死 passs = 123456   for i in range(3):     password = int(input('请输入密码:'))     if password == passs :       print('登录成功')       break     else:       print('请重试')   else:     print('您已三次输入密码错误,锁死')

 

4.例4

#随机生成四位数字验证码 import random yanzhengma = random.randrange(1000,9999) print(yanzhengma)   5.例5 #简易购物车 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()

 

6.例6

#注册用户

def Users():   users_ = input('请输入用户名:')   Z = '123456789'   N = 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'   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:     phone()   else:     print('密码必须大于6位,请重试') def phone():   import re   compile = re.compile('str')   compile.search   compile.findall     pho = input('请输入手机号:')   if len(pho) == 11:     verify()   else:     print('手机号输入错误,请重试')   global_count = 0 def verify(): #声明变量是全局的   global global_count   import random   import time   yanzhengma = random.randrange(1000,9999)   global_count +=1   start_time = time.time()   print('向您手机发送的验证码为: %d'%yanzhengma)   veri = int(input('请输入验证码:'))     end_time = time.time()   sub_time = end_time - start_time     if sub_time > 2:   if global_count>2:     print('请稍后重试。')     exit()   print('验证码超时,即将重新发送')   time.sleep(2)   verify()
  else:     if yanzhengma == veri:       print('注册成功')     else:       print('验证码错误,请重试')       time.sleep(2)       verify() def Start():   print('请注册:')   Users()   Start()

 

 

标签:%.,False,day0203,2f,time,print,input
来源: https://www.cnblogs.com/wqs-Time/p/11285296.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有