Python编程快速上手——让繁琐工作自动化
1号寝林某人
这个作者很懒,什么都没留下…
展开
-
7.18.2 strip()的正则表达式版本
import redef Mystrip(delStr , para=''): if para =='': delS = re.compile(r'\S+(.|\n)*\S+') return delS.search(delStr).group() return re.sub(para, '', delStr)while 1: p...原创 2019-08-18 16:13:55 · 229 阅读 · 0 评论 -
3.11.1 Collatz序列+3.11.2 输入验证
python:def collatz(): global inputnum try: a=int(inputnum) if a%2==0: print(a//2) return a//2 else: print(3*a+1) retu...原创 2019-08-09 21:02:55 · 275 阅读 · 0 评论 -
4.10.1 逗号代码
def func(somepara): ans='' for i in range(len(somepara)-1): ans += somepara[i]+',' ans += 'and '+somepara[i+1] print(ans)spam=['apple', 'banana', 'tofu', 'cats']func(spam)...原创 2019-08-10 12:52:15 · 304 阅读 · 0 评论 -
4.10.2 字符图网格
grid = [['.', '.', '.', '.', '.', '.'], ['.', '0', '0', '.', '.', '.'], ['0', '0', '0', '0', '.', '.'], ['0', '0', '0', '0', '0', '.'], ['.', '0', '0', '0', '0', '0'],...原创 2019-08-10 13:03:50 · 437 阅读 · 0 评论 -
5.6.1 好玩游戏的物品清单+5.6.2 列表到字典的函数,针对好玩游戏的物品清单
#5.6.1import pprintstuff = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}def displayInventory(inventory): print("Inventory:") item_total = 0 for k, v in inventor...原创 2019-08-15 20:02:04 · 322 阅读 · 0 评论 -
6.3 口令保管箱
pw.py#! python3# pw.py - An insecure password locker programimport pyperclipimport sysprint('hello world')PASSWORDS = {'email': 'F7minldfjadjfdf', 'bolg': 'VmALvdfasdfsdfd', 'luggage': '12345...原创 2019-08-17 17:15:46 · 216 阅读 · 0 评论 -
6.4 在WIki标记中添加无序列表
import pyperclip# list 0f 1# list of 2# list of 3text = pyperclip.paste()pyperclip.copy(text)lines = text.split('\n')for i in range(len(lines)): lines[i] = '*' + lines[i]text = '\n'.join...原创 2019-08-17 17:43:21 · 594 阅读 · 0 评论 -
6.7 表格打印
def printTable (tabledata): colWidths = [0]*len(tabledata) lines = len(tabledata) cols = len(tabledata[0]) for i in range(lines): col_max_len = 0 for j in range(cols):...原创 2019-08-17 21:32:40 · 157 阅读 · 0 评论 -
7.18.1 强口令检测
import redef IsStrongPW(passwd): flag =True if len(passwd) < 8: print('Length is too short.') flag = False Num = re.compile(r'.*\d.*') if Num.search(passwd) == ...原创 2019-08-18 15:30:44 · 233 阅读 · 0 评论