download:Django入门到进阶-适合Python小白的系统课程

掌握Django的基础知识,学习Web的相关扩展知识,学会开发c/s服务与apiserver服务;学习多方面非Django内置模块的配置开发方法;学习真正生产环境的服务器最终部署方案;全面阐述Web开发的各个环节的知识点,让你在使用或不使用Django进行开发的情况下都可以顺利上手基于Python的Web服务,尽量涉及绝大部分Python Web开发的生态,并且做讲解知识浅中带细,易于理解,对初学者友好

适合人群
入门Python刚刚接触Web开发的同学
做Python运维的同学(基于Django开发相关Web业务)
做Python测试的同学
技术储备要求
掌握Python基础
了解前端基础
import random
2 if name =="main": #四位數字字母考證码的生成
3 checkcode="" #保管考證码的變量
4 for i in range(4):
5 index=random.randrange(0,4) #生成一個0~3中的數
6 if index!=i and index +1 !=i:
7 checkcode +=chr(random.randint(97,122)) # 生成a~z中的一個小寫字母
8 elif index +1==i:
9 checkcode +=chr(random.randint(65,90) ) # 生成A~Z中的一個大寫字母
10 else:
11 checkcode +=str(random.randint(1,9)) # 數字1-9
12 print(checkcode)
復製代码
輸出爲:m47A、8wQ9、vugS


2。格式化時間函數

1 def formatTime(longtime):
2 '''格式化時間的函數'''
3 import time
4 return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(longtime))

3。記载顯現登錄日誌實例

復製代码
import time
def show_info():
print('''輸入提示數字,執行相應操作
0:退出
1:查看登錄日誌
''')
def write_loginfo(username):
"""
將用戶名和登錄時間寫入日誌
:param username: 用戶名
"""
with open('log.txt','a') as f:
string = "用戶名:{} 登錄時間:{}\n".format(username ,time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
f.write(string)
def read_loginfo():
"""
讀取日誌
"""
with open('log.txt','r') as f:
while True:
line = f.readline()
if line == '':
break # 跳出循環
print(line) # 輸出一行内容
if name == "main":

輸入用戶名

username = input('請輸入用戶名:')# 檢測用戶名while len(username) < 2 :    print('用戶名長度應不少於2位')    username = input('請輸入用戶名:')# 輸入密码password = input('請輸入密码:')# 檢測密码while len(passw ord) < 6 :    print('密码長度應不少於6位')    password = input('請輸入密码:')print('登錄勝利')write_loginfo(username)  # 寫入日誌show_info()              # 提示信息num = int(input('輸入操作數字:')) # 輸入數字while True:    if num == 0:        print('退出勝利')        break    elif num == 1:        print('查看登錄日誌')        read_loginfo()        show_info()        num = int(input('輸入操作數字:'))    else:        print('您輸入的數字有誤')        show_info()        num = int(input('輸入操作數字:'))

3。模仿淘寶客服自動回復
復製代码
1 # 任務2:模仿淘寶客服自動回復
2
3 def find_answer(question):
4 with open('reply.txt','r') as f :
5 while True:
6 line=f.readline()
7 if not line: #也能夠爲if line==''
8 break
9 keyword=line.split('|')[0]
10 reply=line.split('|')[1]
11 if keyword in question:
12 return reply
13 return '對不起,沒有妳想要找的問題'
14
15 if name =='main':
16 question=input('請輸入想要發問的内容:')
17 while True:
18 if question=='bye':
19 break
20 reply=find_answer(question)
21 if not reply:
22 question=input("小蜜不懂您在說什麼,您能夠問一些與订單、账戶和支付相關的内容(退出請輸入bye):")
23 else:
24 print(reply)
25 question=input("您能夠問一些與订單、账戶和支付相關的内容(退出請輸入bye):")
26 print('谢谢,再見!')
27
復製代码

復製代码

4。求最大條約數和最小公倍數 (辗轉相除法)
最大條約數:指兩個或多個整數共有約數中最大的一個

最小公倍數:兩個或多個整數公有的倍數叫做它們的公倍數,其中除0以外最小的一個公倍數就叫做這幾個整數的最小公倍數

二者關係:兩個數之積=最小公倍數*最大條約數

復製代码
1 a=int(input('輸入數字1:'))
2 b=int(input('輸入數字2:'))
3 s=a*b
4 while a%b!=0:
5 a,b=b,(a%b)
6 print(a)
7 print(b)
8 else:
9 print(b,'is the maximum common divisor最大條約數')
10 print(s//b,'is the least common multiple,最小公倍數')
復製代码
更相減损法

復製代码
1 a=int(input('please enter 1st num:'))
2 b=int(input('please enter 2nd num:'))
3 s=a*b
4
5 while a!=b:
6 if a>b:
7 a-=b
8 elif a<b:
9 b-=a
10 else:
11 print(a,'is the maximum common divisor')
12 print(s//a,'is the least common multiple')
13
14 #運轉結果
15 please enter 1st num:40
16 please enter 2nd num:60
17 20 is the maximum common divisor
18 120 is the least common multiple

©著作权归作者所有:来自51CTO博客作者mb60197e37b2213的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. 玩转算法面试-- Leetcode真题分门别类讲解
  2. Tornado从入门到进阶 打造支持高并发的技术论坛
  3. 协程原理从入门到精通 每个后端开发都需要掌握的高性能开发技术
  4. 算法与数据结构-综合提升 C++版
  5. 我的第八个代码
  6. BADI Copy PR item text to PO when ME21N
  7. (EXIT)Copy PR header text to PO header when ME21N
  8. (BADI)Copy PR header text to PO header when ME21N
  9. 这样规范写代码,同事直呼“666”

随机推荐

  1. .net中关于异步性能测试的示例代码
  2. C# ArrayListd的长度问题解决
  3. C#中关于ActiveMQ的应用详解
  4. 关于WebSocket部署服务器外网无法连接的
  5. C#使用AForge实现摄像头录像功能的案例
  6. .Net Core之实现下载文件的实例
  7. c#之浮点数计算问题的解决
  8. C#单例模式的实现以及性能对比的实例
  9. C#之FastSocket实战项目的示例分享
  10. .NET支付宝App支付接入的实例分析